How can I have one winsock listen for connections, and when a connection is made, hand it off to another winsock in an array, then free up the listening one? I want to make a multi-user chat program.
Thanx
Printable View
How can I have one winsock listen for connections, and when a connection is made, hand it off to another winsock in an array, then free up the listening one? I want to make a multi-user chat program.
Thanx
This idea has been around on the forums for some time, and MSDN addressed it once:
Declare a global variable called maxConnections:
Public maxConnections as Integer
Put a Winsock control on your form, name it WSock1, set the LocalPort property to whatever you want your server listening on (e.g, 80 for HTTP), and set the Index property to 0.
In the Form_Load event, set maxConnections to 0 and start the socket with the Listen method. Then, in the ConnectionRequest event:
Code:Private Sub ConnectionRequest(Index as Integer,requestID as Long)
If Index = 0 Then
maxConnections = maxConnections + 1
Load WSock(maxConnections)
WSock(maxConnections).LocalPort = 0
WSock(maxConnections).Accept requestID
End If
End Sub
Thanks! I would have searched for it, instead of asking it, because I know it was on the forum somewhere, but I searched manually for a while, and I couldn't find it. I wish the search was enabled again. It's so much easier to get answers with that, then it is to ask the same question over and over again. Thanks again for answering my question.