2013-06-26 45 views
4

我正在用EventMachine构建一个程序,有时弱客户端上的客户端会触发我们程序中的解除绑定。我想知道如何确定为什么解除绑定功能被触发,以及是否有任何事情可以帮助这些弱客户。EventMachine解除绑定原因

+0

Ehhm。重新连接? https://github.com/eventmachine/eventmachine/blob/master/lib/eventmachine.rb#L762? – fl00r

回答

1

由于某些原因连接终止时,将调用解除绑定,通常需要重新连接到服务器。

class MyConnection < EM::Connection 
    def initialize(host, port) 
    @host, @port = host, port 
    @retry = 0 
    end 

    def self.connect(host, port, timeout) 
    EM.connect(host, port, 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 
0

看来你也可以定义一个 “理由” 参数取消绑定:

def unbind(reason=nil) 
end 

裁判:

https://groups.google.com/forum/#!topic/eventmachine/9HFuXS15HYg https://github.com/eventmachine/eventmachine/issues/362

+0

我看着这个,但当我试图在最新的事件机器宝石上使用此代码时,原因保持为零。对你起作用吗? – user2525752

+0

如果原因是零这意味着“一些其他的原因” - 你可以问新手们关于它...... – rogerdpack