From daf88a33a1cc8cd905e821607dfeace0b5f6c71f Mon Sep 17 00:00:00 2001 From: Maxired Date: Thu, 20 Feb 2014 16:11:33 +0100 Subject: [PATCH 1/2] allow binding of client ip on a specific port --- lib/agent.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/agent.js b/lib/agent.js index 79d1e639..03b07e31 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -59,6 +59,10 @@ Agent.prototype._init = function initSock() { that._handle(msg, rsinfo) }) + if(this._opts.port){ + this._sock.bind( this._opts.port ); + }; + this._sock.on('error', function(err) { // we are skipping DNS errors if(err.code !== 'ENOTFOUND') From f7b6499f6b7fcbca02c1093614b3617e6aa75732 Mon Sep 17 00:00:00 2001 From: maxired Date: Thu, 20 Feb 2014 20:29:41 +0100 Subject: [PATCH 2/2] add test for port binding --- test/end-to-end.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/end-to-end.js b/test/end-to-end.js index 4ee8670a..3306495b 100644 --- a/test/end-to-end.js +++ b/test/end-to-end.js @@ -265,4 +265,20 @@ describe('end-to-end', function() { }) }) }) + + it("should use the port binded in the agent", function(done){ + var agent = new coap.Agent({port: 3636}) + , req = coap.request({ + port:port + , method:'GET' + , pathname :'a' + , agent:agent + }).end() + + server.on('request', function(req, res){ + res.end('hello'); + expect(req.rsinfo.port).eql(3636); + done(); + }); + }); })