• All the examples I saw work on different ports (for example 80 + 8800, ...) I'm just starting an acquaintance. And for my project you need this functionality.

  • Here is snippet that may help. You could use port 80 if wished.


    var server = require('ws').createServer(servePage);

      server.on("websocket", function(ws) {
        ws.on('message', function(evt){
        // handle the message


  • How should I write this together with:

    var server = require("http").createServer();


  • It's just as shown here: http://www.espruino.com/ws#websocket-ser­ver

    Creating a WebSocket server on a port also creates an HTTP server on that same port. You can see that onPageRequest gets called in the example, and that's exactly the same function that'd get called if you did http.createServer(onPageRequest).listen(­8080);.

    Hope that helps!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

How can I create WebServer and WebSocket on one port (80)?

Posted by Avatar for user85997 @user85997