Jump to content
  • Advertisement
Sign in to follow this  
Matty_alan

Managing a client disconnection

This topic is 3123 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I have a loop in my program that sends data to all my clients that looks like this value = 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

Share this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Quote:
Original post by Matty_alan
But 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.

Share this post


Link to post
Share on other sites
Quote:
Original post by Antheus
Flush 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.

Share this post


Link to post
Share on other sites
Quote:
Original post by Matty_alan

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.


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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!