Created
October 30, 2017 14:23
-
-
Save zlatkov/f80b07e00a28f3428b11aac5f5977872 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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