1

I have a server that disconnects frequently

$echo "GET hosts" | nc localhost 323
a.host.com
b.host.com
c.host.com

While reading the same thing from ruby with following code

s = TCPSocket.new(host,port)
s.puts "GET hosts\n\n\r\r"
data = ""
begin
  until s.closed?
    l = s.gets
    puts "Host:" + l
    data = data + l
  end
rescue Exception => e
  puts "pp" + e.message
end

prints out

Host:a.host.com
Host:b.host.com
Host:c.host.com
Host:Error reading from 3: Connection reset by peer

And the application hangs, somehow. Any heads up for this?? Weird thing is that it is not entering the exception handler.

Saurajeet
  • 1,088
  • 2
  • 8
  • 10

1 Answers1

0

You can try rescuing like that rescue Errno::ECONNRESET => e.

Check out How to catch error Connection reset by peer (Errno::ECONNRESET), especially the retry bit.

Community
  • 1
  • 1
Benjamin Tan Wei Hao
  • 9,621
  • 3
  • 30
  • 56