node/server.js
function findPort(cb) {
    var port = tryPort;
    tryPort += 1;

    var server = net.createServer();
    server.listen(port, function(err) {
        server.once('close', function() {
            cb(port);
        });
        server.close();
    });
    server.on('error', function(err) {
        log("port " + tryPort + " is occupied");
        findPort(cb);
    });
}
function findPort(cb) {
    var port = tryPort;
    tryPort += 1;

    var server = net.createServer();
    server.listen(port, function(err) {
        server.once('close', function() {
            cb(port);
        });
        server.close();
    });
    server.on('error', function(err) {
        log("port " + tryPort + " is occupied");
        findPort(cb);
    });
}
function findPort ( cb ) { var port = tryPort ; tryPort += 1 ; var server = net . createServer ( ) ; server . listen ( port , function ( err ) { server . once ( 'close' , function ( ) { cb ( port ) ; } ) ; server . close ( ) ; } ) ; server . on ( 'error' , function ( err ) { log ( "port " + tryPort + " is occupied" ) ; findPort ( cb ) ; } ) ; }
get an empty port for the java server
get an empty port for the java server