Jump to content
  • Advertisement
Sign in to follow this  

[.net] TcpClient.Connected question

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

The Connected property gets the connection state of the Client socket as of the last I/O operation. When it returns false, the Client socket was either never connected, or is no longer connected. Because the Connected property only reflects the state of the connection as of the most recent operation, you should attempt to send or receive a message to determine the current state.
What I don't get is this: I only try to read (attempt to receive) if tcpClient.GetStream().DataAvailable is true, and so, can Connected in this case ever be set to false except on send attempts? I mean, how do I attempt to receive? If there isn't any DataAvailable then I can't read anything, and so I can't test if it is Connected by trying to read, because if it is not connected, then DataAvailable will never be true because it can't receive anything if it is not connected... or am I missing something here? :P

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!