-
If I was to make a server application (LAN), and I want to use winsock, how do I accept more than one connection?
Do I have to Load a new winsock component for each connection, like have one winsock to start with, then if one connects, another one is loaded etc.
But won't this create a conflict if they all listen to the same port?
Any solution is a good solution :)
D
-
See Using the Winsock Control - paragraph "Accepting More than One Connection Request".
-
Thanks, I've done that now. It works...
D
-
Now, a new problem.
If someone disconnects, the wsock that that person used, is still there. That means that a new wsock is loaded for every new connection even though lots of wsocks are available.
I tried this code, but I wasn't allowed to change the index...
---------
Unload TcpServer(Index)
For i = Index + 1 To intMax
TcpServer(i).Index = TcpServer(i).Index - 1
Next
intMax = intMax - 1
---------
D
-
Try looping through the control array looking for the first socket that has been closed and do another Accept.
I haven't tried this but I think it should work. Let me know if it requires any other steps. I don't think it will because I have seen my socket state go from sckConnected to sckClosing to sckClosed when the other side shut down. So with a state of sckClosed, you should be able to do the Accept.
-
sock(0) is listening
NumSocks is the total number of socks
----------------
connection request
for a = 1 to NumSocks
if sock(a).state = 0 then 50
next a
NumSock=NumSocks+1
load sock(NumSocks)
a=NumSocks
50
Sock(a).accept requestid
etc etc