Permalink
Browse files

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

  • Loading branch information...
1 parent 189f92d commit ede7cf47b464fc0b18c9c02a195fa24f15ec5f72 @janpieper janpieper committed Jan 11, 2012
Showing with 4 additions and 5 deletions.
  1. +1 −1 lib/server.js
  2. +3 −4 test/test.js
View
@@ -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
@@ -5,22 +5,21 @@
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(){
/**
* Client.
*/
- var client = net.createConnection(port);
+ var client = net.createConnection(server.address().port);
/**
* Timeout support.

0 comments on commit ede7cf4

Please sign in to comment.