PDA

Click to See Complete Forum and Search --> : Winsock Server app


Dragev
Oct 9th, 2000, 08:44 AM
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

ccoder
Oct 9th, 2000, 02:37 PM
See Using the Winsock Control (http://msdn.microsoft.com/library/devprods/vs6/vbasic/vbcon98/vbconusingwinsockcontrol.htm) - paragraph "Accepting More than One Connection Request".

Dragev
Oct 10th, 2000, 04:16 AM
Thanks, I've done that now. It works...

D

Dragev
Oct 10th, 2000, 06:20 AM
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

ccoder
Oct 10th, 2000, 04:46 PM
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.

kurtsimons
Oct 12th, 2000, 12:32 PM
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