检测 eventmachine 断开连接并测试重新连接

发布于 2024-12-27 06:38:10 字数 363 浏览 2 评论 0原文

我正在尝试在事件机器之上构建一个系统,该系统将检测 TCP 连接何时失败,并测试是否可以触发重新连接。我已经浏览了所有的 eventmachine 代码,但似乎无法找到连接超时或重新连接时的连接回调。尽管我已经在代码中设置了时间,但挂起的连接上没有回调,并且如果我尝试重新启动重新连接,我不会收到有关连接是否成功或失败的反馈。我正在使用它来有效地连接到 telnet 接口。

EventMachine.run do
c = EventMachine.connect "10.8.1.99",5000,ConnectInterface
c.pending_connect_timeout = 10

如有

任何帮助,我们将不胜感激。

I'm trying to build a system ontop of event machine that will detect when a TCP connection has failed and will test to see if a reconnect can be fired. I've gone through all of the eventmachine code but can't seem to find where there is a callback for the connection either timing out in action or in reconnection. Even though I've set the times in the code, there is no callback on the pending connect, and if I try to re fire reconnect I get no feedback as to whether the connection has succeeded or failed. I'm using it to connect to effectively a telnet interface.

EventMachine.run do
c = EventMachine.connect "10.8.1.99",5000,ConnectInterface
c.pending_connect_timeout = 10

end

Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧时光的容颜 2025-01-03 06:38: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
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
尸血腥色 2025-01-03 06:38:10

EventMachine 为此提供了 unbind 方法:

module ConnectInterface
  def connection_completed
    puts "connected"
  end

  def unbind
    puts "disconnected"
  end
end


EM::run do
  EM::connect("10.8.1.99", 5000, ConnectInterface)
end

请注意,无论您是否触发了断开连接,都会在断开连接时调用 unbind 方法。

EventMachine provide the unbind method for this:

module ConnectInterface
  def connection_completed
    puts "connected"
  end

  def unbind
    puts "disconnected"
  end
end


EM::run do
  EM::connect("10.8.1.99", 5000, ConnectInterface)
end

be aware The unbind method will get called on disconnect whether you triggered the disconnect or not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文