Sign in to follow this  

How do I know if a client disconnected?

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);


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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this