Created
May 13, 2011 14:27
-
-
Save vitobotta/970623 to your computer and use it in GitHub Desktop.
Example of BrB Client with auto reconnec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Client | |
attr_reader :hostname, :host, :port | |
def initialize(port, host) | |
@port, @host = port, host | |
connect! | |
EM.reactor_thread.join | |
end | |
def connect! | |
@server = BrB::Tunnel.create(self, "brb://#{host}:#{port}") do |type, tunnel| | |
if type == :unregister | |
sleep 2 | |
connect! | |
else | |
on_connected | |
end | |
end | |
end | |
def on_connected | |
# something to do when the connection is | |
# successfully established or restored | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment