Helper method for testing; returns the TCP port used for this
        registration, even if it was specified as 0 and thus allocated by the
        OS.
559684
def getPort(self):
        
        disp = self.pbmanager.dispatchers[self.portstr]
        return disp.port.getHost().port
368871
def get_port_monitor(self):
        
        uri = "{}{}".format(self.data["uri"], self.PORT_MONITOR_PATH)
        return self._helper.do_get(uri)
125673
public int getPort()
    {
        if (port != 0) {
            return port;
        }
        else {
            final Connector connector = connectorHolder.get();
            if (connector != null) {
                Preconditions.checkState(connector.getLocalPort() > 0, "no port was set and the connector is not yet started!");
                return connector.getLocalPort();
            }
            else {
                return 0;
            }
        }
    }
689887
def start(self, tcpport=102):
        
        if tcpport != 102:
            logger.info("setting server TCP port to %s" % tcpport)
            self.set_param(snap7.snap7types.LocalPort, tcpport)
        logger.info("starting server on 0.0.0.0:%s" % tcpport)
        return self.library.Srv_Start(self.pointer)
641226
def bind_tcp_socket(address):
    
    host, port = address
    for res in set(socket.getaddrinfo(host, port, socket.AF_INET,
                                      socket.SOCK_STREAM, 0,
                                      socket.AI_PASSIVE)):

        family, socktype, proto, _, sock_addr = res
        sock = socket.socket(family, socktype, proto)
        if os.name != 'nt':
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

        # Automatic port allocation with port=None.
        sock.bind(sock_addr)
        sock.listen(128)
        bound_port = sock.getsockname()[1]
        return sock, (host, bound_port)

    raise socket.error('could not bind socket')
878274
def __check_port(self, port):
        
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            s.bind((_host(), port))
            return True
        except socket.error:
            return False
        finally:
            s.close()
163574
private int getPort() {
		String port = getGangliaConfig(args.getPort(), ganglia, "port",
				DEFAULT_PORT);
		return Integer.parseInt(port);
	}
1128068
def get_unused_port(port=None):
    """"""
    if port is None or port < 1024 or port > 65535:
        port = random.randint(1024, 65535)
    assert(1024 <= port <= 65535)
    while True:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            s.bind(('', port))  # Try to open port
        except socket.error as e:
            if e.errno in (98, 10048):  # 98, 10048 means address already bound
                return get_unused_port(None)
            raise e
        s.close()
        return port
476211
def port(self):
        """"""
        self._port = self.lib.iperf_get_test_server_port(self._test)
        return self._port
896422
def find_free_port():
    """"""
    with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock:
        sock.bind(('', 0))
        return sock.getsockname()[1]
1209223
def remove_tcp_port(self, port):
        

        if port in self._used_tcp_ports:
            self._used_tcp_ports.remove(port)
504408
public String getHost()
    {
        if (_addr==null)
            return __0_0_0_0;
        
        return _addrIsHost?_addr.getHostName():_addr.getHostAddress();
    }
741974
def allocate_port():
    
    sock = socket.socket()
    try:
        sock.bind(("localhost", 0))
        return get_port(sock)
    finally:
        sock.close()
762558
async function findWindowsPortRange() {
  // First, check if we're running on XP.  If this initial command fails,
  // we just fallback on the default IANA range.
  let stdout = await execute('cmd.exe /c ver');
  if (/Windows XP/.test(stdout)) {
    // TODO: Try to read these values from the registry.
    return {min: 1025, max: 5000};
  } else {
    stdout = await execute('netsh int ipv4 show dynamicport tcp');
    /* > netsh int ipv4 show dynamicport tcp
      Protocol tcp Dynamic Port Range
      ---------------------------------
      Start Port : 49152
      Number of Ports : 16384
     */
    let range = stdout.split(/\n/)
        .filter((line) => /.*:\s*\d+/.test(line))
        .map((line) => Number(line.split(/:\s*/)[1]));
    return {
      min: range[0],
      max: range[0] + range[1]
    };
  }
}
135250
def port_free?(host, port)
      Addrinfo.tcp(host, port).listen.close

      true
    rescue SocketError, Errno::EADDRINUSE, Errno::EACCES
      false
    end
796017
public static int getAvailablePort() {
		for (int i = 0; i < 50; i++) {
			try (ServerSocket serverSocket = new ServerSocket(0)) {
				int port = serverSocket.getLocalPort();
				if (port != 0) {
					return port;
				}
			}
			catch (IOException ignored) {}
		}

		throw new RuntimeException("Could not find a free permitted port on the machine.");
	}
1230577
def get_host_port(spec, default_port):
    ""
    args = (spec.split(':', 1) + [default_port])[:2]
    args[1] = int(args[1])
    return args[0], args[1]