ruby – EventMachine解除绑定的原因
发布时间:2020-12-17 02:04:50 所属栏目:百科 来源:网络整理
导读:我正在使用EventMachine构建一个程序,有时弱上网的客户端会在我们的程序中触发unbind.我想知道如何确定解除unbind函数的原因以及我是否可以做些什么来帮助这些弱客户端. 解决方法 当连接因某种原因终止时,将调用Unbind,通常需要重新连接到服务器. class MyCo
我正在使用EventMachine构建一个程序,有时弱上网的客户端会在我们的程序中触发unbind.我想知道如何确定解除unbind函数的原因以及我是否可以做些什么来帮助这些弱客户端.
解决方法
当连接因某种原因终止时,将调用Unbind,通常需要重新连接到服务器.
class MyConnection < EM::Connection def initialize(host,port) @host,@port = host,port @retry = 0 end def self.connect(host,port,timeout) EM.connect(host,self,host,port) end def connection_completed @retry = 0 end def unbind if @retry < 3 EM.add_timer(1){ @retry +=1 && reconnect(@host,@port) } else fail "Can't reconnect" end end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |