Socket.Connected

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,
I'm playing with Socket and Telnet (via hyperterminal). I'm trying to
display a message when the client disconnect, that is when hyperterminal
either close the connection, or is closed, on the client side. But,
Socket.Connected always seems to return true, even though I do as in the doc
and do a 0 byte Send before checking its value.

Is there another way to know if a Socket is still connected to a client?

Etienne Fortin
 
Etienne said:
Hi there,
I'm playing with Socket and Telnet (via hyperterminal). I'm trying to
display a message when the client disconnect, that is when hyperterminal
either close the connection, or is closed, on the client side. But,
Socket.Connected always seems to return true, even though I do as in the
doc and do a 0 byte Send before checking its value.

Is there another way to know if a Socket is still connected to a client?

Try to do a receive on the socket. It normally returns the number of bytes
received.. but when the connection has been closed it will return 0 bytes.

hth,
Max
 
Thanks for your answer.

It is a probably a good way to know if a connection is dead. But what about
the situation when the client didn't send any data for a certain period of
time, but it is still connected and alive? Receive() will return zero bytes.

Etienne
 
Etienne said:
It is a probably a good way to know if a connection is dead. But what
about the situation when the client didn't send any data for a certain
period of time, but it is still connected and alive? Receive() will return
zero bytes.

If you are using blocking sockets, Receive will not return 0 bytes unless
the client disconnected. If you call Receive but there is no data
available, Receive will block and wait until there is data available or
until the client disconnects (in which case it would return 0 bytes).

Max
 
Back
Top