Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

socket listener

Status
Not open for further replies.

leangross

IS-IT--Management
Jul 3, 2002
84
PH
im creating a socket listener and just wondering if there is a way the listener can detect if the client is no longer connect to it (listner)?

thanks!

 
Using the TCPListener you get a TCPClient object to communicate with the 'Client'.

If you use the TCPClient.GetStream.BeginRead method to read the data from the 'Client', then when the 'Client' closes the connection, the CallBack from the BeginRead will contain no data (0 Bytes).
 
yeah you're partially correct but client can still be connected even if it is not sending any data to the listener. is there other way of knowing if client is still connected or not?
 
Well, from what I know and use, the client is connected until the server side of the connection receives a 0 lengthed data, which indicates the point when the connection is closed.
 
From what I can tell there will always be a case where the connection could still be open. You can easily detect just about everything except a dropped connection - ie client pulled the plug, or a mid-point station failed, etc...

The only way to account for every thing is to implement a Ping-Pong system - or basically make sure there is a regular timed transmission between client and server (server initiates, client responds). If the client doesn't respond in a timely manner the connection is considered closed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top