• Advertisement
Sign in to follow this  

How do I know if a client disconnected?

This topic is 2446 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
oh... lol.. I had read the docs, but I guess I read them too fast :P

sorry

Share this post


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

  • Advertisement