Provide fallback when port is already in use

27 views
Skip to first unread message

Jarek Foksa

unread,
Mar 6, 2012, 6:56:03 AM3/6/12
to Socket.IO
The code below will throw an error If port 9999 is already in use:

websocketIO = require 'websocket.io'
server = websocketIO.listen(9999);

Instead of breaking the execution of the script, is there a way to
provide a fallback? E.g. if port 9999 is already in use, check port
9998 instead.

I have already tried wrapping the code above with try/catch statements
without success.

Guillermo Rauch

unread,
Mar 6, 2012, 9:51:03 AM3/6/12
to sock...@googlegroups.com
Pass a function callback and look for an Error object as first parameter. Then try listening gain on a different port.
--
Guillermo Rauch
LearnBoost CTO
http://devthought.com

Reply all
Reply to author
Forward
0 new messages