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
fl00r source share