我正在尝试在事件机器之上构建一个系统,该系统将检测 TCP 连接何时失败,并测试是否可以触发重新连接。我已经浏览了所有的 eventmachine 代码,但似乎无法找到连接超时或重新连接时的连接回调。尽管我已经在代码中设置了时间,但挂起的连接上没有回调,如果我尝试重新启动重新连接,我不会收到有关连接是否成功或失败的反馈。我使用它来有效连接到 telnet 接口(interface)。
EventMachine.run do
c = EventMachine.connect "10.8.1.99",5000,ConnectInterface
c.pending_connect_timeout = 10
结束
任何帮助将不胜感激。
最佳答案
module MyCallBack
def unbind # define your unbind method
puts "#{@@ip}: #{@@port}"
puts "-- disconnected from remote server!"
puts "-- attempting reconnection"
reconnect @@ip, @@port # use reconnect, already provided by EventMachine
end
end
关于ruby - 检测 eventmachine 断开连接并测试重新连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8889230/