Skip to content

Instantly share code, notes, and snippets.

@kenpratt
Created July 19, 2013 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kenpratt/6042782 to your computer and use it in GitHub Desktop.
Save kenpratt/6042782 to your computer and use it in GitHub Desktop.
var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({port: 8088})
, _ = require("underscore");
var connections = [];
wss.on('connection', function(ws) {
connections.push(ws);
ws.on('message', function(message) {
console.log('received: %s', message);
});
ws.send('something');
});
setTimeout(function() {
console.log("closing sockets");
_.each(connections, function(ws) { console.log("closing socket"); ws.close(); });
console.log("closing server");
wss.close();
}, 5000);
console.log("this server will shut down in 5s. please connect to it quickly.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment