Created
July 19, 2013 22:26
-
-
Save kenpratt/6042782 to your computer and use it in GitHub Desktop.
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
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