From: "Iñaki Baz Castillo" Date: 2010-01-13T07:37:01+09:00 Subject: Re: TCPSocket doesn't detect remote disconnection inmediatelly El Martes, 12 de Enero de 2010, Aaron Turner escribió: > Long story short, what you're seeing with Ruby is not a bug, but > rather how TCP sockets work. TCP sockets are bi-directional and when > one side "closes" the connection, they are not actually causing the > TCP session to tear down as telnet implies, but rather is informing > the other end of the connection that they have no more data to send. > The receive direction is still technically open via TCP, although the > HTTP protocol specifies no more communication is possible. Understood, thanks a lot. Then I wonder if there is some way to detect that the remote has closed its side. When it occurs the remote sends a TCP segment with ACK+FIN flags enabled. Is there a way to detect it in Ruby using TCPSocket? if there some attribute of the socket object that changes whe such ACK+FIN arrives? (however I've tried most of the TCPSocket methods and found nothing). The underlaying system of courses knows it as in case a new TCP segment is sent (by the Ruby client) it's sent with big PUSH enabled, knowing that the remote will reply with RESET flag enabled. Is the Ruby TCPSocket aware that its message is sent with PUSH flag enabled? if so it could raise something (optionally) so I know that I'll get no response and could reconnect and retry. Is it possible? Humm, I think that all this stuff is done at kernel TCP layer so the socket user has nothing to deal with... am I right? > I also recommend "Unix Network Programming (vol 1)" by Stevens if you > want to understand the details of sockets and network communication. > Since network programming utilizes much of the same API constructs as > file IO, many newbie network programmers make these sorta mistakes > because they expect network sockets to behave like file descriptors > when they do not. Sure. Thanks a lot. -- Iñaki Baz Castillo