Results 1 to 3 of 3

Thread: Multiple Winsock connections

  1. #1

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125

    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
    <removed by admin>

  2. #2
    Addicted Member csammis's Avatar
    Join Date
    Mar 2001
    Location
    /dev/null
    Posts
    226
    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!"

  3. #3

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    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.
    <removed by admin>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width