Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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");
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #socket #io #ports
ADD COMMENT
Topic
Name
3+6 =