}
var req = { oncomplete: afterConnect };
- if (addressType == 6) {
- err = self._handle.connect6(req, address, port);
- } else if (addressType == 4) {
- err = self._handle.connect(req, address, port);
+ if (addressType === 6 || addressType === 4) {
+ port = port | 0;
+ if (port <= 0 || port > 65535)
+ throw new RangeError('Port should be > 0 and < 65536');
+
+ if (addressType === 6) {
+ err = self._handle.connect6(req, address, port);
+ } else if (addressType === 4) {
+ err = self._handle.connect(req, address, port);
+ }
} else {
err = self._handle.connect(req, address, afterConnect);
}
net.createConnection(tcpPort, 'localhost').on('connect', cb);
net.createConnection(tcpPort, cb);
net.createConnection(tcpPort, 'localhost', cb);
+
+ assert.throws(function () {
+ net.createConnection({
+ port: 'invalid!'
+ }, cb);
+ });
});
process.on('exit', function() {