开发者

How to detect TCP Client disconnect in Ruby

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜