1

I'm building and application that uses many sockets, in some cases, two socket.io servers try to start with the same tcp port (this is expected actually), so one of them crashes with Error: EADDRINUSE.

What I want is to "catch" the error and then do something about it. I mean, the error in some cases is expected, but I want to handle it properly. I can't find a way to do it.

Thanks!

Laerion
  • 805
  • 2
  • 13
  • 18
  • 1
    Like http://stackoverflow.com/questions/9544479/how-do-i-catch-node-js-express-server-errors-like-eaddrinuse ? – crackmigg May 19 '16 at 17:06
  • Show us your code where you're starting up the webSocket listener and we'll show you how to add appropriate error handling. You should handle the error right where you're calling `.listen()`. – jfriend00 May 20 '16 at 06:58

1 Answers1

-1

Thanks to @migg for his answer. The link provided contained two solutions, this one worked for me:

process.on('uncaughtException', function(err) {
    if(err.errno === 'EADDRINUSE')
        console.log(...);
    else
        console.log(err);
    process.exit(1);
});
Laerion
  • 805
  • 2
  • 13
  • 18