views:

36

answers:

1

In order to check the client servers is alive at anytime, I use the long tcp connecting to deal with this.

So is there any method to detect the long tcp connect from client servers? it's good to do with Ruby

+1  A: 

Assuming you want to detect if a server is not responding in a timely manner, then you can use the timeout function of Net::HTTP.

http = Net::HTTP.new(uri.host, uri.port)
http.open_timeout = http.read_timeout = 1.0 #seconds

Then when you perform a Get or other Net::HTTP action, you can rescue Exception, or specifically the timeout exception, to do something on timeout.

Mark Thomas