Results 1 to 7 of 7

Thread: [RESOLVED] Winsock: How to Receivie Multiple Conexions?

  1. #1

    Thread Starter
    Addicted Member bulletrick's Avatar
    Join Date
    Jul 2005
    Location
    Philippines
    Posts
    248

    Resolved [RESOLVED] Winsock: How to Receivie Multiple Conexions?

    Guys, I know that to have a server that can receive multiple client conexions, i must create a single Winsock Control that has an index of zero (for example, Winsock1(0)), right?

    What would then be the code I need to write to serve multiple conexions? It's like I am creating multiple Winsock controls at run time, right?

    Please help! Thanks a lot!

  2. #2
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: Winsock: How to Receivie Multiple Conexions?


  3. #3
    Addicted Member
    Join Date
    Apr 2005
    Posts
    129

    Re: Winsock: How to Receivie Multiple Conexions?

    you need to set up a winsock array.

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Winsock: How to Receivie Multiple Conexions?

    Quote Originally Posted by fgp123
    you need to set up a winsock array.
    Firstly please if you post, write answers that you would liek to see. That helps no-one.

    Ok onto the question, you are correct you need to draw 1 winsock control onto your form, which for the purposes of this post I will call Winsock. Ok then you need to set the index property to 0 hich is actually making your winsock control (winsock) an aray. Now then from here every time a new client connects you create a new winsock control to handle there connection.

    Ok so the connection request method would change to this,

    VB Code:
    1. Private Sub Winsock_ConnectionRequest(Index As Integer, ByVal RequestID As Long)
    2.  
    3.   Load Winsock(Winsock.UBound + 1)
    4.  
    5.   Winsock(Winsock.UBound).Accept RequestID
    6. End Sub

    That simply lets multiple users connect by creating a new winsock control (+ 1 of the uBound ) each time somone trys to connect.

    The next thing you will need to do is adjust your servers data arrival event

    VB Code:
    1. Private Sub Winsock_DataArrival(index As Integer, ByVal bytesTotal As Long)
    2.  
    3. Winsock(index).GetData Data
    4.  
    5. msgbox Data
    6. end sub

    A final snippet of code, is used for the server to send data to every client connected. It simply loops through checks to see if the client is connected if it is it will send data!

    VB Code:
    1. For i = 0 To Winsock.Count - 1
    2.       If Winsock(i).State = sckConnected Then
    3.           Winsock(i).SendData Data
    4.           DoEvents
    5.       End If
    6.     Next i

    When moving to multiple connections the client stays the same, it is only the server and the logic that changes, the 2 links below should assist you more, if you have any more questions though please post.


    http://www.winsockvb.com/article.php?article_id=18
    http://www.winsockvb.com/article.php?article_id=19

    Pino
    Last edited by Pino; Jan 10th, 2006 at 06:34 AM.

  5. #5

    Thread Starter
    Addicted Member bulletrick's Avatar
    Join Date
    Jul 2005
    Location
    Philippines
    Posts
    248

    Re: Winsock: How to Receivie Multiple Conexions?

    Thanks for the link, Pino! Very helpful! Too bad, I can't give you any more reps...

  6. #6
    Hyperactive Member Rattlerr's Avatar
    Join Date
    Jul 2005
    Location
    FloralCity,Florida
    Posts
    269

    Re: Winsock: How to Receivie Multiple Conexions?

    yeah,thxs I found that link useful also with the project i'm starting for Winsock..

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Winsock: How to Receivie Multiple Conexions?

    Hehe,

    Thanks for the feedback.

    Pino

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