El Martes, 12 de Enero de 2010, Iñaki Baz C.
The TCP connection is terminated when you call TCPSocket#close.
Yes, I’m realizing of it right now. There must be some error in my code
which prevents the socket from being closed. I must investigate it.
I’ve found the cause of my issue. My ruby script listens into a pipe and
a message is received it’s sent via the TCPSocket.
Also there is a thread which does @socket.gets("\r\n") to receive the
responses. In this way I can I can send multiple requests to the server
without waiting for the responses. Instead the thread doing “gets” reads
responses, parses a request identifier and that’s all.
But in this case when calling socket.close the connection is not
@socket = TCPSocket.new(server, port)
res = @socket.gets("\r\n")
When “@socket.close” is called it’s just closed “at Ruby level”, this
cannot write/read from it as I get “closed pipe” error (which makes
However the TCP connection remains open at OS level (in ESTABLISHED
netstat shows in both the client and server).
But it’s really interesting (for me) the following fact:
Without the line @socket.close netstat output shows (during the sleep
tcp 0 0 192.168.1.10:51112 18.104.22.168:5062 ESTABLISHED
But when running the script with @socket.close line then I see:
tcp 0 0 192.168.1.10:51112 22.214.171.124:5062 ESTABLISHED -
It’s like if the Ruby process (irb) has detached itself from the socket
process pid in the netstat output for that connection), but the socket
open at OS level.
Is it the expected behavior?