It's connected. Later the server is stoped or restarted so the TCP
connection gets down. But if in the client I send data using
"@socket.send" then it gets no error at all, it behaves as if the data
has been sent through the socket.
I expected that there should be some method to get the status of the
socket, but I cannot find it. Any suggestion please?
However, if the client sends data again (using TCPSocket#send) then it
gets an exception. Why doesn't such exception occur in the firs case?
it's obvious that the connection has been closed by the other
endpoint.
Thanks,.
···
2011/3/16 Iñaki Baz Castillo <ibc@aliax.net>:
It's connected. Later the server is stoped or restarted so the TCP
connection gets down. But if in the client I send data using
"@socket.send" then it gets no error at all, it behaves as if the data
has been sent through the socket.
After the server closes its side of the socket, there must be some
amount of time after which if the client tries to send data over the
socket, the client will receive a broken pipe error. Is that 2.3 years?
Or, closer to five minutes?
Here is a very technical diagram that includes what happens when one
side closes the socket:
Determining whether a network connection is still live is generally a
pretty complex thing. Usually the most reliable way to find out the
status of a connection is to use it. IIRC there are some socket
options that can influence shutdown behavior and timing. See for
example here for general description of socket options
This question comes up on the CocoaAsyncSocket list periodically. Robbie
Hanson's post (the third one down), explains what is happening at the OS
level:
It's possible that your first send() is stuck in a buffer. See if
calling flush() on the socket works.
Determining whether a network connection is still live is generally a
pretty complex thing.
Using EventMachine (to connect to a TCP server) the #unbind method is
inmediately called when the endpoint closes the connection.
Usually the most reliable way to find out the
status of a connection is to use it. IIRC there are some socket
options that can influence shutdown behavior and timing. See for
example here for general description of socket options http://linux.die.net/man/7/socket
This question comes up on the CocoaAsyncSocket list periodically. Robbie
Hanson's post (the third one down), explains what is happening at the OS
level:
It's possible that your first send() is stuck in a buffer. See if
calling flush() on the socket works.
Determining whether a network connection is still live is generally a
pretty complex thing.
Using EventMachine (to connect to a TCP server) the #unbind method is
inmediately called when the endpoint closes the connection.
No, it is immediately called when your local network stack determines
that the socket is closed. That is a hugely different thing! IP
networking is actually quite complex and behaves differently than,
say, an unnamed pipe between two local processes. "UNIX Network
Programming" by W. Richard Stevens used to be the standard book on the
matter; I guess today you'll find such information on the web as well.
Usually the most reliable way to find out the
status of a connection is to use it. IIRC there are some socket
options that can influence shutdown behavior and timing. See for
example here for general description of socket options http://linux.die.net/man/7/socket