Last active
December 15, 2015 19:39
-
-
Save bodokaiser/5313146 to your computer and use it in GitHub Desktop.
Gist to try out different API designs for node-websockets WebSocketServer.
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
// for small text messages | |
wsserver.on('message', function(message, wssocket) { | |
wsserver.broadcast(message); | |
}); | |
// for large, fragmented messages | |
wsserver.on('stream', function(request, response) { | |
response.select([2, 4, 5]); | |
request.pipe(response); | |
}); | |
// for ping frames | |
wsserver.on('pong', function(message, wssocket) { | |
console.log('ping: ' + message.toString(); | |
}); | |
// for close frames | |
wsserver.on('close', function(code, wssocket) { | |
wsserver.broadcast(wssocket.id + 'left us'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment