Dynamic ports allocation

Recently, I deployed Licode on one of the productions servers at my company
where I am interning. As with most such servers, most of the ports were
blocked and the handful of the ones that were open weren’t the ones that
Licode uses by default. So I went through the code to figure out the places
where this change needed to be made to use the ports that were open. Then I
figured, it would be better if I can change them dynamically and this is my
solution for that. I added these elements in the config object of
’licode_config.js’:

config.httpServerPort = 8101;
config.erizoControllerPort = 1936;
config.nuvePort = 1935;

You can change these ports as required. These are the files that need to be
changed that reflect these new ports now:

  1. Erizo Controller Port
    1. In the file,
      licode/erizo_controller/erizoController/erizoController.js
      1. Add this line: var config = require(’./…/…/licode_config’);
      2. Change line 13 to server.listen(config.erizoControllerPort);
    2. In the file, licode/nuve/nuveAPI/resource/tokensResource.js
      1. Add the line: var config =
        require(’./…/…/…/licode_config.js’);
      2. Change line 118 to: token.host = ec.ip + ‘:’ +
        config.erizoControllerPort;
    3. Nuve Port
    4. In the file licode/nuve/nuveAPI/nuve.js
      1. Add this line, var config = require(’./…/…/licode_config.js’);
      2. Change line 70 to: app.listen(config.nuvePort);
    5. HttpServerPort
    6. In the file, licode/extras/basic_example/basicServer.js or similar
      1. Change line 41 to: N.API.init(config.nuve.superserviceID,
        config.nuve.superserviceKey, ‘http://localhost:’ + config.nuvePort + ‘/’);
      2. Change line 89 to: httpServer.listen(config.httpServerPort);

You will be able to access this code at localhost:<config.httpServerPort>.
This setup is working fine for me. Hope this works well enough for others
too. Leave your feedback here in a reply. :slight_smile: