Permalink
Browse files

Merge pull request #9 from adcloud/feature/listen-on-random-port

Allow port=0 to let the kernel choose a random unprivileged port.
  • Loading branch information...
2 parents 189f92d + ede7cf4 commit 3520521a8031d41ddf8ea0662b04640df0739252 @tj 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 3520521

Please sign in to comment.