EventMachine Unleashes the Mind

I create a program with EventMachine, and sometimes clients on weak Internet will run unbind in our program. I was wondering how I can determine why the unbind function is running, and if I can do something to help these weak clients.

+4
source share
2 answers

Unbind is called when the connection is terminated for any reason, usually you need to connect to the server.

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 
+1
source

you can also define unbind with the "reason" parameter:

 def unbind(reason=nil) end 

refs:

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

0
source

Source: https://habr.com/ru/post/1488368/


All Articles