   Managing a client disconnection
  Hey guys,I have a loop in my program that sends data to all my clients that looks like thisvalue = send(clientx, buffer, bufsize, 0);However if send trys to send to a disconnected user it will return -1, error 10054(Connection Reset By Client) and then by the time it loops around to the next send I get Error 10055(Full Buffer).I done some poking around on "The Google" and found that the best way to mangage this is by using SO_LINGER, or TCP_NODELAY, using setockopt but iv'e slapped them into my program and nothing happened.So the question here is do I set the socket up like that after it errors, error 10054, sorta like this?value = send(clientx, buffer, bufsize, 0);Error = WSAGetLastError();if(Error == 10054){setsockopt(clientx, SO_LINGER, 1, buffer, buffersize);closesocket(clientx);}Or has the socket already been closed automaticly and i need to setsockopt's eariler in the program, like on the sockets creation? Do I need to still flush the buffer manually? or am I takling this the wrong way completely??cheers Matty   
  If a TCP connection is lost, you have to reconnect in a proper way. The nodelay only affects the nagle-algorithm.   ;  But if i didn't want to reconnect to the client and just flush the buffer clean Would I just shutdown the socket and close it? Or do I have to make another call to flush the buffer?   ;  But if i didn't want to reconnect to the client and just flush the buffer clean Would I just shutdown the socket and close it? Or do I have to make another call to flush the buffer?   ;Quote:Original post by Matty_alanBut if i didn't want to reconnect to the client and just flush the buffer clean Flush to whom? Peer is gone. It's pinnin' for the Fjords. It is bereft of life. It is an Ex-Peer.Quote:Would I just shutdown the socket and close it?Yes.;Quote:Original post by AntheusFlush to whom? Peer is gone. It's pinnin' for the Fjords. It is bereft of life. It is an Ex-Peer.Sorry i'm a bit of a noob, I think my terminology is wrong, I just want to clear the buffer to be used by the next command so it wont error,could I just do something like buffer = NULL; or would that be doing something incredibly stupid and\or wouldn't work.   ;Quote:Original post by Matty_alanSorry i'm a bit of a noob, I think my terminology is wrong, I just want to clear the buffer to be used by the next command so it wont error,could I just do something like buffer = NULL; or would that be doing something incredibly stupid and\or wouldn't work.Network stack allocates internal buffers that it uses to coalesce data, hold it until confirmed, and similar. Whenever send is called, data from user buffer is copied into this internal buffer. The internal buffer is not accessible by user, it may be hidden deep inside of kernel.In case of such send error there is no need to linger, since the peer is gone and nothing can be sent anymore. closesocket should be enough in this case. Linger might be used for clean disconnect to flush data, but that is somewhat tricky, since we're shutting down already, and linger might or might not complete in time, or might time out.   