|
-
May 29th, 2001, 07:49 PM
#1
Thread Starter
PowerPoster
Multiple Winsock connections
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
-
May 29th, 2001, 09:01 PM
#2
Addicted Member
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
Things I've Said:
"Life's funny like that...elephants can wear frilly lace panties, and Dubya still looks like a monkey in a big chair"
"Take four goats and strap one to each foot of a llama. Presto, goat-powered llama!"
"You want to get me to work more, get me a Coke. No? Then deal with inferior garbage, I'm not coding another line and your clients can go to......thanks, I'd love a Coke right about now!"
-
May 29th, 2001, 10:36 PM
#3
Thread Starter
PowerPoster
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|