code: function isFree(port, opt_host) {
    var result = promise.defer(function() {
      server.cancel();
    });
  
    var server = net.createServer().on('error', function(e) {
      if (e.code === 'EADDRINUSE') {
        result.fulfill(false);
      } else {
        result.reject(e);
      }
    });
  
    server.listen(port, opt_host, function() {
      server.close(function() {
        result.fulfill(true);
      });
    });
  
    return result.promise;
  }
docs: Tests if a port is free.
  @param {number} port The port to test.
  @param {string=} opt_host The bound host to test the {@code port} against.
  Defaults to {@code INADDR_ANY}.
  @return {!webdriver.promise.Promise.<boolean>} A promise that will resolve
  with whether the port is free.