Skip to content

Instantly share code, notes, and snippets.

@ramainen
Created September 5, 2014 13:28
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 ramainen/3c738641fc7fbe3ca6fc to your computer and use it in GitHub Desktop.
Save ramainen/3c738641fc7fbe3ca6fc to your computer and use it in GitHub Desktop.

Client:

var table_id = 1; // example, python will give this value

var socket = io('http://localhost:3000/table'+table_id');
socket.on('connect', function() {
	console.log('Connected');
	socket.emit('join', "table_"+table_id);
});

Server:

var nsp = [io.of('/table1'), io.of('/table2')];

for(key in nsp){
	nsp[key].on('connection', function(socket){
		socket.on('join', function(table) {
			console.log('joined to table '+table);
		});
		socket.on('message', function(message) {
			nsp[key].emit('hi', 'everyone!');
		});
	});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment