Last active
December 20, 2015 02:49
-
-
Save whistler/6059645 to your computer and use it in GitHub Desktop.
How to use socket.io-client to keep retrying for server or connect to a different server
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
client = require 'socket.io-client' | |
socket = null | |
host = "http://localhost:12345" | |
connect_client = () -> | |
console.log('connecting') | |
socket = client.connect(host, {'force new connection': true}) | |
socket.on('connect', ()-> | |
console.log('connected') | |
) | |
socket.on('error', (err)-> | |
reconnect() | |
) | |
connect_client() | |
reconnect = () -> | |
# optionally change host here | |
socket.removeAllListeners() if socket | |
setTimeout(go, 1000) |
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
require 'socket.io' | |
socketio = require('socket.io').listen(12345, {'log':false}) | |
socketio.on('connection', (socket)-> | |
console.log('hello') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment