Skip to content

Commit

Permalink
Merge pull request #18 from maxired/ClientPortBinding
Browse files Browse the repository at this point in the history
Allow binding of an Agent to a specific port
  • Loading branch information
mcollina committed Feb 21, 2014
2 parents a629495 + f7b6499 commit 5bed763
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
16 changes: 16 additions & 0 deletions test/end-to-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
})

0 comments on commit 5bed763

Please sign in to comment.