|
-
Mar 17th, 2005, 11:04 PM
#1
Thread Starter
Member
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:
Private Sub ListenSock_ConnectionRequest(ByVal requestID As Long)
For FindOpenSock = 0 to 1024
If Sock(FindOpenSock).State = sckClosed Then
Sock(FindOpenSock).Accept requestID
ListenSock.Close
ListenSock.Listen
Exit Sub
End If
Next FindOpenSock
End Sub
I mean it looks like it should be fine to me, but it always screws up. BIG THANKS IN ADVANCE!!!
-Mike
-
Mar 18th, 2005, 12:12 AM
#2
Re: Multiple Winsock controls accepting connections
ListenSock.Close closed the current one, and opened with the next open number
-
Mar 18th, 2005, 12:18 AM
#3
Thread Starter
Member
Re: Multiple Winsock controls accepting connections
 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
-
Mar 18th, 2005, 12:44 AM
#4
Re: Multiple Winsock controls accepting connections
Sock(0) will give you an open port.
-
Mar 18th, 2005, 09:42 AM
#5
Frenzied Member
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:
Private Sub Sock_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
For FindOpenSock = 1 to 1024
If Sock(FindOpenSock).State = sckClosed Then
Sock(FindOpenSock).LocalPort = 0
Sock(FindOpenSock).Accept requestID
Exit Sub
End If
Next FindOpenSock
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|