From: Lars Christensen Date: 2010-01-12T20:20:27+09:00 Subject: Re: How to close a TCP socket? (TCPSocket#close doesn't close it) On Tue, Jan 12, 2010 at 11:43 AM, Iñaki Baz Castillo wrote: > Hi, perhaps I miss something but when I close a TCP connection using > TCPSocket#close the connection remains as OS level for long seconds (minutes). > > Be reading the doc: > >  IO#close > >  Closes ios and flushes any pending writes to the operating system. The >  stream is unavailable for any further data operations; an IOError is raised >  if such an attempt is made. I/O streams are automatically closed when they >  are claimed by the garbage collector. > > So, does it mean that the TCP connection is *really* terminated when the > garbage collector removes it (some seconds/minutes after calling > TCPSocket#close)? The TCP connection is terminated when you call TCPSocket#close. > Unfortunatelly it's not valid for me, I need the capability to close a TCP > connection and open a new one without mantaining two parallel connections. > > Any other way to really close a TCP connection at OS level? Thanks. Why do you need to do that? Your connection is in the TIME_WAIT state, which is exists for good reasons. There are no parallel connections.