Socket.Connected

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
 
M

Markus Stoeger

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
 
G

Guest

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
 
M

Markus Stoeger

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top