Skip to content

Instantly share code, notes, and snippets.

@zlatkov
Created October 30, 2017 14:23
Show Gist options
  • Save zlatkov/f80b07e00a28f3428b11aac5f5977872 to your computer and use it in GitHub Desktop.
Save zlatkov/f80b07e00a28f3428b11aac5f5977872 to your computer and use it in GitHub Desktop.
// We'll be using the https://github.com/theturtle32/WebSocket-Node
// WebSocket implementation
var WebSocketServer = require('websocket').server;
var http = require('http');
var server = http.createServer(function(request, response) {
// process HTTP request.
});
server.listen(1337, function() { });
// create the server
wsServer = new WebSocketServer({
httpServer: server
});
// WebSocket server
wsServer.on('request', function(request) {
var connection = request.accept(null, request.origin);
// This is the most important callback for us, we'll handle
// all messages from users here.
connection.on('message', function(message) {
// Process WebSocket message
});
connection.on('close', function(connection) {
// Connection closes
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment