CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2000
    Posts
    163

    Connecting with WinSock

    Hello

    How can I connect more then two users with winsock. ??? (like in chat)

    Thanks


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Connecting with WinSock

    The thing you need to do is to make a control array. Doing this at run-time is very flexible, and can serve up to as many connections as your system is capable of (read as hardware restrictions). To do this, place one Winsock control on teh form, give it index 0. When a connection request comes in, create a socket, and accept the connection.

    private ConnectionCount as Integer

    private Sub Winsock1_ConnectionRequest(Index as integer, RequestID as long)
    ConnectionCount = ConnectionCount + 1
    Load Winsock1(ConnectionCount)
    Winsock1(ConnectionCount).Accept RequestID
    End Sub

    private Sub Winsock1_DataArrival(Index as integer, .....
    Dim strData as string
    Winsock1(Index).GetData strData
    Msgbox "incoming data from connection " & Index & vbcrlf & strData
    End Sub




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Jul 2001
    Location
    maharashtra,india
    Posts
    181

    Re: Connecting with WinSock

    what Cakkie said is right
    but to get a clear idea u can go to
    planetsourcecode.com
    there u will find many chat projects
    i hope there u will get what u want

    best of luck


  4. #4
    Join Date
    Dec 2000
    Posts
    163

    Re: Connecting with WinSock

    What I do with the LocalPort and RemotePort ?
    Can I use same ports for all clients ?


  5. #5
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Connecting with WinSock

    Oops, forgot, you need to set the localport. Typically, start counting from a number, and add the ConnectionCount to it. Do this before you issue the Accept method.

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  6. #6
    Join Date
    Dec 2000
    Posts
    163

    Re: Connecting with WinSock

    I found.
    Thanks.

    I use with same port for all users


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

Featured