Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can provide ip to bind on client mode (only udp) #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
8 changes: 6 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
};

Expand Down