diff --git a/lib/client.js b/lib/client.js index bf204d4..def8f9b 100644 --- a/lib/client.js +++ b/lib/client.js @@ -61,6 +61,12 @@ var Request = exports.Request = function(opts) { if (!this.server || !this.server.address || !net.isIP(this.server.address)) throw new Error('Server object must be supplied with at least address'); + if (this.server.bind && !net.isIP(this.server.bind)) + throw new Error('Server object bind attribute must be an IP address'); + + if (this.server.bind && this.server.type == 'tcp') + throw new Error('Bind attribute is not supported on tcp mode, sorry'); + if (!this.server.type || ['udp', 'tcp'].indexOf(this.server.type) === -1) this.server.type = 'udp'; diff --git a/lib/utils.js b/lib/utils.js index 47bf497..80ed8b7 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -24,7 +24,8 @@ var dgram = require('dgram'), net = require('net'), util = require('util'); -var UDPSocket = exports.UDPSocket = function(socket, remote) { +var UDPSocket = exports.UDPSocket = function(socket, remote, bind) { + this._bind = bind; this._socket = socket; this._remote = remote; this._buff = undefined; @@ -72,7 +73,10 @@ UDPSocket.prototype.bind = function(type) { self.emit('close'); }); - this._socket.bind(); + if (this._bind) + this._socket.bind(null, this._bind); + else + this._socket.bind(); } };