in reply to Detecting a closed socket

I don't understand why you need to determine if the socket is "closed" or not. If you look at this simple example from Q&A you see that the server never "opens" or "close" a socket but it does create a socket and "accepts" connections from clients and then reads from the socket. The server detects that client has stopped sending data when the client terminates and its socket is destoryed. For a more complicated client/server system the client could signal the server that it has finished sneding data by sending some sort of flag or by telling the server how much data to expect. Also for a more than trival server you will need to fork the server after it does the accept because while it is reading from the socket no other clients will be able to connect. The clients can only connect when the server is doing an accept. ... I think :)

Replies are listed 'Best First'.
Re: Re: Detecting a closed socket
by Flame (Deacon) on Aug 05, 2003 at 07:40 UTC
    Heh, it's a little more complex than a simple file-server, and I have it working, just having a hard time telling when the other side leaves... the protocol I'm using has no 'goodbye' (perhaps I should do something about that)

    My code doesn't have bugs, it just develops random features.

    Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)