Q:

Running two socket servers on same port

I have three servers 

Main server - which listens to all HTTP request
Socket Server 1 : Listen to X types of socket request
Socket Server 2 : Listen to Y types of socket request

I want to run all three servers using same IP:Port combination and all three servers have different hostname. I have updated local DNS i.e. /etc/hosts to resolve all three domain names to same IP, take 127.0.0.1 for instance. 
I am using VHost to resolve the requests on basis of hostname and directing request to appropriate server. Here is the code for that :
var express = require('express');
var vhost = require('vhost');
var app = express();
var https = require('https');

var mainServer =  <hostname1> ;
var socketServer1 = <hostname2> ;
var socketServer2 = <hostname3>;

var server = https.createServer(<options>, app);

server.listen(<somePort>,function(){
    console.log('VHost running');
});

var mainApp = require('./app.js');
var socketServerApp1 = require('./socketServer1');
var socketServerApp2 = require('./socketServer2');

app.use(vhost(mainServer, mainApp));
app.use(vhost(socketServer1, socketServerApp1(server)));
app.use(vhost(socketServer2, socketServerApp2(server)));

The problem I am facing in above code is, if I try to run both socket servers, the browser throws an error like :
WebSocket connection to 'wss://socketServer1:8443/socket.io/?EIO=3&transport=websocket&sid=qlSXz3os5eDI8c_EAAAC' failed: Connection closed before receiving a handshake response

But if there is only one socket server running at a time, then things works fine for that socket server i.e. if I comment one of app.use like :
app.use(vhost(mainServer, mainApp));
app.use(vhost(socketServer1, socketServerApp1(server)));
//  app.use(vhost(socketServer1, socketServerApp2(server)));

Is it not possible to run two socket servers on same IP:Port combination?

A:

The problem was that both socket servers were having separate listners, which was causing the error. Moving socket listner to vhost App fixes the problem . Following is the code :
var express = require('express');
var vhost = require('vhost');
var app = express();
var https = require('https');
var socketio = require('socket.io');

var mainServer =  <hostname1> ;
var socketServer1 = <hostname2> ;
var socketServer2 = <hostname3>;

var server = https.createServer(<options>, app);
var io = socketio.listen(server);

server.listen(<somePort>,function(){
    console.log('VHost running');
});

var mainApp = require('./app.js');
var socketServerApp1 = require('./socketServer1');
var socketServerApp2 = require('./socketServer2');

app.use(vhost(mainServer, mainApp));
app.use(vhost(socketServer1, socketServerApp1(io)));
app.use(vhost(socketServer2, socketServerApp2(io)));

