Skip to content

Instantly share code, notes, and snippets.

@jdeisenberg
Last active January 3, 2016 04:23
Show Gist options
  • Save jdeisenberg/597f5121fd2d1906ea30 to your computer and use it in GitHub Desktop.
Save jdeisenberg/597f5121fd2d1906ea30 to your computer and use it in GitHub Desktop.
socket stuff
var sockets = [null, null, null];
var areas = ["main", "auxiliary", "extras"];
function receive_message(event) {
console.log(event.data);
}
function open_connections() {
for (var i = 0; i < sockets.length; i++) {
sockets[i] = new WebSocket("ws://localhost:3001");
sockets[i].onmessage = receive_message;
var closure_fcn = function(socket, area) {
return function(event) {
console.log(socket);
console.log(area);
socket.send(area);
}
}
sockets[i].onopen = closure_fcn(sockets[i], areas[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment