forked from shokai/websocket-client-simple
-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Hi, which is the correct way to manage a reconnect when the connection is lost?
I tried this code:
def relay_connect(relay_host)
ws = WebSocket::Client::Simple.connect(relay_host)
ws.on :open do |event|
# ....
end
ws.on :message do |msg|
# ....
end
ws.on :error do |event|
puts "Error, reconnecting..."
sleep(5)
ws = nil
relay_connect(relay_host)
end
ws.on :close do |event|
# p [:close, event.code, event.reason]
puts "Reconnecting..."
sleep(5)
ws = nil
relay_connect(relay_host)
end
end
relay_connect(relay_host)
loop do
STDIN.gets.strip
end
But it does not work.
It doesn't give any output when I block the network, while the CPU spikes up at 100%.
Any help :)
unasuke
Metadata
Metadata
Assignees
Labels
No labels