From: Robert Klemme Date: 2011-03-18T00:02:09+09:00 Subject: Re: TCPSocket: how to realize that the other endpoint has closed the connection? On Thu, Mar 17, 2011 at 12:06 PM, Iņaki Baz Castillo wrote: > 2011/3/17 Robert Klemme : >> On Thu, Mar 17, 2011 at 3:38 AM, 7stud -- wrote: >>> 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 >> >> and how to apply them >> http://www.ruby-doc.org/stdlib/libdoc/socket/rdoc/classes/BasicSocket.html#M003703 > > Ok, I'll check such socket options. > Thanks a lot. YWC Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/