 |
|

02-24-2005, 04:35 PM
|
|
Centurion
|
|
Join Date: Dec 2004
Location: New York
Posts: 111
|
|
multiple connections to port?
|
anyone know who to have multiple connections to a single server? Sofar I can only have one user connected to my server, and its not fun to talk to your self.
|
|

02-24-2005, 05:12 PM
|
 |
Senior Contributor
|
|
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
|
|
|

02-24-2005, 05:26 PM
|
|
Centurion
|
|
Join Date: Dec 2004
Location: New York
Posts: 111
|
|
Finally some one answers to one of my posts here! ive been waiting for hours!!!
Ok, I actualy just started learning Winsock last night, and i learned what I know so far from winsockvb.com.
I got up to the multiple connections tut, and this is where i got lost. I could not follow that at all, it was very poorly written. I got the basic idea down, but since Im totaly new to this, and visual basic in general (5 months) it didnt really help much.
This is what I got after reading those tutorials, and surfing the web for about 5 hours.
I am stuck on an error message that says:
"Procedure does not match description of event or procedure having same name "
It points to the top line of code that I have include below. Private sub ....
Code:
Private Sub Winsock_ConnectionRequest(Index As Integer, ByVal RequestID As Long)
For i = 0 To UBound(Winsock)
Next i
Winsock.Close
Winsock.Accept RequestID
End Sub
End Sub
I dont know where to go from here.
|
|

02-24-2005, 05:42 PM
|
 |
Senior Contributor
|
|
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
|
|
|
you have to set the index property on your control to 0 on your form
and then your going to want to change those to Winsock(Index).whatever
and maybe you should go back and re-read one or both of those tutorials, i know the first one is pretty clear and clean, you've got several mistakes there.
|
|

02-24-2005, 05:44 PM
|
|
Centurion
|
|
Join Date: Dec 2004
Location: New York
Posts: 111
|
|
It was set to 0 when i got that error message.
If i had executed the program before with it having no index, would I need to replace the old winsock with a new one? Because before when I was just having one connection It had no index value. It wasnt until I started trying to add multiple connections that I gave it an index value of 0.
Ok, ive made the suggested changes, and ive come up with the same error for this code section.
Code:
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Winsock.GetData strData
For i = 0 To UBound(Winsock)
If Winsock(i).Status = sckConnected Then
Winsock(i).SendData strData
DoEvents
End If
Next i
txtConsole.Text = txtConsole.Text & vbCrLf & strData
txtConsole.SelStart = Len(txtConsole.Text)
End Sub
Ill save time and post my whole source file here for viewing.
Code:
Option Explicit
Private Sub Form_Load()
Winsock.LocalPort = 10101
Winsock.Listen
End Sub
Private Sub Winsock_ConnectionRequest(Index As Integer, ByVal RequestID As Long)
Load Winsock(Winsock.UBound + 1)
Winsock(Winsock.UBound).Accept RequestID
For i = 0 To UBound(Winsock)
Next i
Winsock(Index).Close
Winsock(Index).Accept RequestID
End Sub
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Winsock.GetData strData
For i = 0 To UBound(Winsock)
If Winsock(i).Status = sckConnected Then
Winsock(i).SendData strData
DoEvents
End If
Next i
txtConsole.Text = txtConsole.Text & vbCrLf & strData
txtConsole.SelStart = Len(txtConsole.Text)
End Sub
|
Last edited by Frantic-; 02-24-2005 at 05:49 PM.
|

02-24-2005, 05:45 PM
|
 |
Senior Contributor
|
|
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
|
|
|
that's right, but you wouldn't have to erplace it, just take away the index. But ya go back and re-read atleast that first tutorial
|
|

02-24-2005, 05:50 PM
|
|
Centurion
|
|
Join Date: Dec 2004
Location: New York
Posts: 111
|
|
|
im reading the 1st tut again, and maybe perhaps i looked at it the wrong way. Am i supposed to at form load have the for loop just createa bunch of winsocks, and then make extra subs and or functions to manage the opening,closing and connecting to the ports, and if all are used then say "Sorry we're full "
Or perhaps the above could be one way to go about it.
|
Last edited by Frantic-; 02-24-2005 at 05:58 PM.
|

02-24-2005, 06:02 PM
|
 |
Senior Contributor
|
|
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
|
|
|
well... you could do it that way, or as i believe that first tut i showed you makes a new control each connection request...
|
|

02-24-2005, 06:05 PM
|
 |
Senior Contributor
|
|
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
|
|
|
well in your DataArrival, you need to add Index As Integer into the parameters of the sub, and then user Winsock(Index) instead of just Winsock
|
|

02-24-2005, 06:09 PM
|
|
Centurion
|
|
Join Date: Dec 2004
Location: New York
Posts: 111
|
|
|
Should I add index into parts that already have a (value) after them?
UBound(Winsock)
should i make it UBound(Winsock(index))
|
|

02-24-2005, 06:13 PM
|
 |
Senior Contributor
|
|
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
|
|
|
no, UBound just takes the name of the array, also in your for loop, don't change those (i) to (Index) you'll need that i to send to all connected clients
|
|

02-24-2005, 06:30 PM
|
|
Centurion
|
|
Join Date: Dec 2004
Location: New York
Posts: 111
|
|
ok im down to what i think if either the last or 2nd last problem, atleast with my server.
I ran into another compilation error, and i tried to fix it, but ran into a second error when i "fixed" it. I will list.
When i ran the code as is, i got a message saying
" Method or data member not found "
and it pointed to winsock.localport = 10101 and highlighted LocalPort =
it pointed to the form load which is located below.
Code:
Private Sub Form_Load()
Winsock.LocalPort = 10101
Winsock.Listen
End Sub
I went and made the following changes to the form load, which are shown below.
Code:
Private Sub Form_Load()
Winsock(index).LocalPort = 10101
Winsock(index).Listen
End Sub
I got this error message.
" variable not defined "
and it pointed to the winsock(index).localport = 10101 and highlighted index.
|
|

02-24-2005, 06:31 PM
|
 |
Senior Contributor
|
|
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
|
|
|
winsock(0) ... your first control...
|
|

02-24-2005, 06:47 PM
|
|
Centurion
|
|
Join Date: Dec 2004
Location: New York
Posts: 111
|
|
Updated form load:
Code:
Private Sub Form_Load()
Dim i As Integer
For i = 1 To 5
Load Winsock(i)
Next i
Winsock(0).LocalPort = 10101
Winsock(0).Listen
End Sub
now its telling me that UBound is an expected array.
|
|

02-24-2005, 06:51 PM
|
 |
Senior Contributor
|
|
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
|
|
|
don't load any to begin with, take that out, and load them like you were before in your connection request
|
|

02-24-2005, 06:57 PM
|
|
Centurion
|
|
Join Date: Dec 2004
Location: New York
Posts: 111
|
|
same error.
"Expected Array"
It it highlighting UBound found in the following code.
Code:
Private Sub Winsock_DataArrival(index As Integer, ByVal bytesTotal As Long)
Dim strData As String
Winsock(index).GetData strData
For i = 0 To UBound(Winsock)
If Winsock(i).Status = sckConnected Then
Winsock(i).SendData strData
DoEvents
End If
Next i
txtConsole.Text = txtConsole.Text & vbCrLf & strData
txtConsole.SelStart = Len(txtConsole.Text)
End Sub
|
|

02-24-2005, 07:17 PM
|
 |
Senior Contributor
|
|
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
|
|
|
oops, lol use Winsock.count -1 instead, i believe it even shows that in one of those tuts
|
|

02-24-2005, 07:20 PM
|
|
Centurion
|
|
Join Date: Dec 2004
Location: New York
Posts: 111
|
|
Ok ive made that change, now its telling me "method or data member not found" for winsock(i).status
Code:
If Winsock(i).Status = sckConnected Then
Code:
Private Sub Winsock_DataArrival(index As Integer, ByVal bytesTotal As Long)
Dim strData As String
Winsock(index).GetData strData
Dim i As Integer
For i = 0 To Winsock.Count - 1
If Winsock(i).Status = sckConnected Then
Winsock(i).SendData strData
DoEvents
End If
Next i
txtConsole.Text = txtConsole.Text & vbCrLf & strData
txtConsole.SelStart = Len(txtConsole.Text)
End Sub
|
|

02-24-2005, 07:28 PM
|
 |
Senior Contributor
|
|
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
|
|
|
where did Status come from? it should be State
|
|

02-24-2005, 07:32 PM
|
|
Centurion
|
|
Join Date: Dec 2004
Location: New York
Posts: 111
|
|
lol, everything i know came from reading online tuts
Ill soon be investing in some nice books, do you have any reccomendations?
Ok this time it actualy compiled!!!
I ran it, and logged on. The client was able to connect, but then the server generated an error dialog box saying
"Invalid Control Array Index"
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|