TooTallNate / node-nat-pmp

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

Example code results in error #4

Open BranchyMcBranchface opened 11 years ago

BranchyMcBranchface commented 11 years ago

Code:

var natpmp = require('nat-pmp');

// create a "client" instance connecting to your local gateway
var client = natpmp.connect('10.0.1.1');

// explicitly ask for the current external IP address
client.externalIp(function (err, info) {
  if (err) throw err;
  console.log('Current external IP address: %s', info.ip.join('.'));
});

// setup a new port mapping
client.portMapping({ private: 8080, public: 8080, ttl: 3600 }, function (err, info) {
  if (err) throw err;
  console.log(info);
  // {
  //   type: 'tcp',
  //   epoch: 8922109,
  //   private: 22,
  //   public: 2222,
  //   ...
  // }
});

Result:

events.js:71
        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 Client.connect (/Users/jake/Dropbox/Development/nat-pmp test/node_modules/nat-pmp/index.js:93:15)
    at Client._next (/Users/jake/Dropbox/Development/nat-pmp test/node_modules/nat-pmp/index.js:205:12)
    at Client.request (/Users/jake/Dropbox/Development/nat-pmp test/node_modules/nat-pmp/index.js:152:8)
    at Client.externalIp (/Users/jake/Dropbox/Development/nat-pmp test/node_modules/nat-pmp/index.js:160:8)
    at Object.<anonymous> (/Users/jake/Dropbox/Development/nat-pmp test/server.js:16:8)