2013-06-26 46 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