For my first win32asm program I am writting a "dumb" ident server. It works fine the first time a server connects, but fails after that. I debugged and found it was failing on the 'accept' function (10022 or 10038).

The question is: From the point you get a FD_CLOSE how do you appropriately get back to 'accept'?

Do you need to closesocket/socket/options/bind/listen?

I have looked at the source codes on Iczelion's site, but I have not found the right combination.

Attached is the ident wndProc (one of many I have tried) minus debug.

The full program with debug (crippled) is here:
http://home.nc.rr.com/bdjames/ident.asm
Posted on 2002-03-01 19:31:30 by bdjames
You're problem is that you are overwriting your socket handle with the return value of accept. You create your socket only once. Each time a connection is accepted with accept(), the return value is the handle of a new socket descriptor for the connection. This socket descriptor is the unique identifier for this specific connection and is lost when the connection is closed. The socket handle you get as a return value from the socket() call is permanent and should not be changed until closesocket() is called for it. Your first connection is successful because your socket handle is stored in hSock and you pass it to accept(). You then move the return value of accept() (the transient socket descriptor for the new connection) into hSock, overwriting your socket handle. On the next accept call, you again pass hSock to accept() only this time it doesn't contain your socket handle, it contains the old socket descriptor value and it fails. You catch my drift...
Posted on 2002-03-01 23:27:31 by rdaneel
I was wondering why that was done, but I did not follow-up. Now I see how to do a real thread based server.

It has been driving me nuts for days. Thank you

So the only reason to open more than one socket is to use more than one port or because you have to kill the winsock due to an error?
Posted on 2002-03-01 23:51:19 by bdjames
That is correct. There has been a lot of discussion in this thread recently about multithreaded winsock apps. You should dig around the recent posts if you want to know more about that.
Posted on 2002-03-02 14:30:32 by rdaneel