diff --git a/lib/net.js b/lib/net.js index 58494019e4e..1daf841edcc 100644 --- a/lib/net.js +++ b/lib/net.js @@ -759,6 +759,8 @@ function doConnect (socket, port, host) { }; } +function isPort (x) { return parseInt(x) >= 0; } + // var stream = new Stream(); // stream.connect(80) - TCP connect to port 80 on the localhost @@ -774,7 +776,7 @@ Stream.prototype.connect = function () { self._connecting = true; // set false in doConnect - if (parseInt(arguments[0]) >= 0) { + if (isPort(arguments[0])) { // TCP var port = arguments[0]; dns.lookup(arguments[1], function (err, ip, addressType) { @@ -991,7 +993,7 @@ Server.prototype.listen = function () { var self = this; if (self.fd) throw new Error('Server already opened'); - if (typeof(arguments[0]) == 'string') { + if (!isPort(arguments[0])) { // the first argument specifies a path self.fd = socket('unix'); self.type = 'unix';