Answers for "socket io across two different ports"

0

socket io across two different ports

global.appRoot = require('app-root-path');

var express = require('express');
var session = require('express-session');
var app = express();

var server1 = app.listen(7788, "0.0.0.0", function() {
    console.log('Server listening on port ' + server1.address().port);
});

var server2 = app.listen(5566, "0.0.0.0", function() {
    console.log('Server listening on port ' + server2.address().port);
});

var socket = require('socket.io').listen(server1);
var socket2 = require('socket.io').listen(server2);

socket.on('connect', function (socket) {
    console.log("hi socket 1");
});

socket2.on('connect', function (socket) {
    console.log("hi socket 2");
});
Posted by: Guest on September-01-2021
0

socket io across two different ports

<!doctype html>
<html>
    <head>
        <script src='https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.1/socket.io.js'></script>
        <script>
            var socketClient1 = io('ws://localhost:5566');
            var socketClient2 = io('ws://localhost:7788');
        </script>
    </head>
    <body>
        <ul id='messages'></ul>
    </body>
</html>
Posted by: Guest on September-01-2021

Browse Popular Code Answers by Language