TooTallNate / node-nat-pmp

Node.js implementation of the NAT Port Mapping Protocol
132 stars 16 forks source link

Unbreak vock #2

Closed indutny closed 12 years ago

indutny commented 12 years ago
/// Vock - VoIP on node.js ///

events.js:66
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: bind EADDRINUSE
    at errnoException (dgram.js:356:11)
    at Socket.bind (dgram.js:123:15)
    at lookup (dgram.js:49:12)
    at UDP.lookup4 [as lookup] (dgram.js:59:10)
    at Socket.bind (dgram.js:120:16)
    at new Client (/private/tmp/node_modules/vock/node_modules/nat-pmp/index.js:78:15)
    at Object.exports.connect (/private/tmp/node_modules/vock/node_modules/nat-pmp/index.js:55:10)
    at Socket.init (/private/tmp/node_modules/vock/lib/vock/socket.js:93:24)
    at new Socket (/private/tmp/node_modules/vock/lib/vock/socket.js:32:8)
    at Object.create (/private/tmp/node_modules/vock/lib/vock/socket.js:42:10)

/cc @drudge

TooTallNate commented 12 years ago

Ya, so the problem is that nat-pmp binds to a udp port. You should call client.close() after doing your thing (like in the examples in the test dir), and that'll free the port.

I think short-lived clients are better in general. Perhaps I'll make the close() call happen automatically if that seems like a good idea.

indutny commented 12 years ago

Well, port may be bound by other client (like second application instance). Why not just wrap it with try/catch and report error in callback?

TooTallNate commented 12 years ago

Ah I didn't realize it was an uncaught exception. Ya, an "error" event should be emitted on the client object. This is a bug.