Skip to content

Instantly share code, notes, and snippets.

@vitobotta
Created May 13, 2011 14:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitobotta/970623 to your computer and use it in GitHub Desktop.
Save vitobotta/970623 to your computer and use it in GitHub Desktop.
Example of BrB Client with auto reconnec
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