bejm
bejm

Reputation: 519

How to start multiple node/socket servers on one machine

I am starting two different node servers, on different ports, but I still get the following error.

info  - socket.io started
info  - FlashPolicyFileServer received an error event:
    listen EADDRINUSE

This is how I am starting the first server:

"use strict";

var 
    express = require('express'),
    app = module.exports = express();

// set some config vars

var 
    server = require('http').createServer(app),
    socket = require('./app/lib/socket');

// these settings are common to both environments
app.configure(function () {
    // configuration left out
    app.use(app.router);

});

//  Load the routing
require('./app/routes')(app);
// run the server with socket.io
server.listen(3001);
socket.listen(server, session, app);

I am starting the second server the exact same way except the second last line is changed to :

server.listen(3002);

socket.io is started like this in another file

exports.listen = function (server, sessionStore, app) {
    var io = require('socket.io').listen(server);
    ...

Not sure how to fix this error.

Upvotes: 3

Views: 679

Answers (1)

Errol Fitzgerald
Errol Fitzgerald

Reputation: 3008

The flash policy port defaults to 10843, so both apps will try to run it off this port, which is the error you are getting. Either remove the transport, or set the port using

io.set('flash policy port', 3005)

Or you can just remove that transport altogether:

io.set('transports', [
    'websocket',
    'xhr-polling',
    'htmlfile',
    'jsonp-polling'
]);     

Upvotes: 1

Related Questions