Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow port=0 to let the kernel choose a random unprivileged port. #9

Merged
merged 1 commit into from

2 participants

@janpieper

If you pass 0 as port to net.Server.listen(<port>, <host>), the kernel will choose a random and free unprivileged port. You can select the selected port with net.Server.address().port.

@tj tj merged commit 3520521 into tj:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 5 deletions.
  1. +1 −1  lib/server.js
  2. +3 −4 test/test.js
View
2  lib/server.js
@@ -105,7 +105,7 @@ Server.prototype.removeClient = function(client){
Server.prototype.listen = function(port, host){
net.Server.prototype.listen.call(
this
- , port || defaultPort
+ , port === 0 || port ? port : defaultPort
, host || defaultHost);
return this;
};
View
7 test/test.js
@@ -5,14 +5,13 @@
var nedis = require('../')
, net = require('net')
- , fs = require('fs')
- , port = 8888;
+ , fs = require('fs');
/**
* Server.
*/
-var server = nedis.createServer().listen(port);
+var server = nedis.createServer().listen(0);
server.on('listening', function(){
@@ -20,7 +19,7 @@ server.on('listening', function(){
* Client.
*/
- var client = net.createConnection(port);
+ var client = net.createConnection(server.address().port);
/**
* Timeout support.
Something went wrong with that request. Please try again.