Jump to content
  • Advertisement
Sign in to follow this  
SelethD

How do I know if a client disconnected?

This topic is 2568 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

I am making a server in c#
I am using TCPClient for the client objects

This is my code for reading data from a client

NetworkStream netStream = Client.GetStream();
if (netStream.CanRead)
{
RecvPacket packet = new RecvPacket();
if ((int)Client.Available < 4) return false;

byte[] header = new byte[4];
netStream.Read(header, 0, 4);

}
netStream.Close();


I have read that a any read that returns a 0 bytes, means the connection is closed.
So how is this done with NetworkStream?
Thanks

Share this post


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

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!