Results 1 to 5 of 5

Thread: Multiple Winsock controls accepting connections

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    56

    Multiple Winsock controls accepting connections

    Hi, I've made a few web servers in the past, and all worked prefectly, minus one critical problem... whenever it would receive more than one connection at a time, it would cancel any current connections and begin the new one. I don't know why, I had 1025 winsock controls.

    Now I am programming a new one that I am determined to get working perfectly, and I think I need some help with that problem. Here's the code I used to use to accept connections:

    VB Code:
    1. Private Sub ListenSock_ConnectionRequest(ByVal requestID As Long)
    2.  
    3. For FindOpenSock = 0 to 1024
    4.      If Sock(FindOpenSock).State = sckClosed Then
    5.           Sock(FindOpenSock).Accept requestID
    6.           ListenSock.Close
    7.           ListenSock.Listen
    8.           Exit Sub
    9.      End If
    10. Next FindOpenSock
    11.  
    12. End Sub

    I mean it looks like it should be fine to me, but it always screws up. BIG THANKS IN ADVANCE!!!

    -Mike

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Multiple Winsock controls accepting connections

    ListenSock.Close closed the current one, and opened with the next open number

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    56

    Re: Multiple Winsock controls accepting connections

    Quote Originally Posted by dglienna
    ListenSock.Close closed the current one, and opened with the next open number
    How do I keep the listening socket open after opening a new connection then? Do I need to just get rid of ListenSock and start with Sock(0) listening and then when it opens, change the listening port to Sock(1) etc??

    thanks!
    -Mike

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Multiple Winsock controls accepting connections

    Sock(0) will give you an open port.

  5. #5
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Re: Multiple Winsock controls accepting connections

    Get rid of ListenSock and listen on Sock(0). Accept the connection on any of Sock(1) through Sock(1024) that is closed.
    VB Code:
    1. Private Sub Sock_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    2.    If Index = 0 Then
    3.       For FindOpenSock = 1 to 1024
    4.            If Sock(FindOpenSock).State = sckClosed Then
    5.               Sock(FindOpenSock).LocalPort = 0
    6.               Sock(FindOpenSock).Accept requestID
    7.               Exit Sub
    8.            End If
    9.       Next FindOpenSock
    10.    End If
    11. End Sub
    Here is a link to the MS example of using the Winsock control: http://msdn.microsoft.com/library/de...ockcontrol.asp The example for multiple connections is towards the end of the article.

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