获取port.

@param $port_num

@return mixed
508365
public function getPort($port_num)
    {
        $ports = $this->server->ports;
        foreach ($ports as $port) {
            if ($port->port == $port_num) {
                return $port;
            }
        }

        return null;
    }
640026
public function getPort()
    {
        if (empty($this->port)) {
            if (array_key_exists($this->scheme, static::$defaultPorts)) {
                return static::$defaultPorts[$this->scheme];
            }
        }

        return $this->port;
    }
1231960
function run($num=1)
    {
        //初始化事件系统
        if(!($this->protocol instanceof Swoole_UDP_Server_Protocol))
        {
            return error(902);
        }
        //建立服务器端Socket
        $this->server_sock = $this->create("udp://{$this->host}:{$this->port}");
        stream_set_blocking($this->server_sock,$this->server_block);
        $this->server_socket_id = (int)$this->server_sock;
        //设置事件监听，监听到服务器端socket可读，则有连接请求
        $this->protocol->onStart();
        $this->server_loop();
    }
1021557
def get_port(self, adapter_number, port_number):
        
        for port in self.ports:
            if port.adapter_number == adapter_number and port.port_number == port_number:
                return port
        return None
1201968
public function setPort($port)
    {
        if (!is_int($port) || $port < 0 || $port > 65535) {
            throw new InvalidArgumentException(
                sprintf('%s only accepts a port between 0 and 65535 inclusive', __FUNCTION__)
            );
        }

        $this->port = $port;

        return $this;
    }
1105033
public function getServerPort()
    {
        if (!$this->port) {
            $default = $this->isSecure() ? 443 : 80;
            $this->setServerPort($this->getServer('SERVER_PORT', $default));
        }
        return $this->port;
    }
126040
private function filterPort(?int $port): ?int
    {
        if ($port === null) {
            return null;
        }

        $port = (int) $port;
        if (1 > $port || 0xffff < $port) {
            throw new \InvalidArgumentException(sprintf('Invalid port: %d. Must be between 1 and 65535', $port));
        }

        return
            !isset(self::$schemes[$this->scheme]) ||
            $port !== self::$schemes[$this->scheme]
                ? $port : null;
    }
87751
public function scanPortRange() {
        if (strtolower($this->typePort) == 'tcp') {
            $hostIp = $this->hostIP;
        } else if (strtolower($this->typePort) == 'udp') {
            $hostIp = "udp://$this->hostIP";
        } else {
            throw new \Exception('Port Type undefined!');
        }

        $errno = $errstr = null;
        for ($portNumber = $this->startPort; $portNumber <= $this->endPort; $portNumber++) {
            $handle = @fsockopen($hostIp, $portNumber, $errno, $errstr, $this->timeout);
            if ($handle) {
                $service = $this->getService($portNumber, strtolower($this->typePort));
                $this->openPorts[$portNumber] = (!empty($service)) ? $service : null;
                fclose($handle);
            }
        }
        return $this->openPorts;
    }
457702
def port(self, port=None):
        
        if (port is None) or (port == self.__port):
            return self.__port
        # when port change ensure old socket is close
        self.close()
        # valid port ?
        if 0 < int(port) < 65536:
            self.__port = int(port)
            return self.__port
        else:
            return None
302692
public function setPort( $port ) : PgSQL
   {

      if ( null === $port )
      {
         $this->_attributes[ 'port' ] = $port;
         return $this;
      }

      $port = false;
      if ( \is_string( $port ) )
      {
         $port = (int) $port;
      }
      else if ( TypeTool::IsInteger( $port ) )
      {
         $port = (int) $port;
      }
      else if ( TypeTool::IsStringConvertible( $port, $portStr ) )
      {
         $port = (int) $portStr;
      }

      if ( ! \is_int( $port ) || ! $this->_supportedAttributes->get( 'port' )->validateValue( $port ) )
      {
         throw new ArgumentException( 'port', $port, 'Invalid port!' );
      }

      $this->_attributes[ 'port' ] = $port;

      return $this;

   }
813985
public static function find($port=null, $proto='tcp') 
    {
        if (null === $port || false === $port) {
            $port = 50000 + rand(0, 1000);
        } else {
            $port = intval($port);
            if ($port < 0 || 49152 < $port) {
                $port = 49152;
            }
        }
        $proto = strtolower($proto);

        do {
            if (self::isPortUsed($port, $proto)) {
                continue;
            }

            if ($proto === 'tcp') {
                $sock = self::_createSocket($proto);
                if (@socket_bind($sock, '127.0.0.1', $port) && @socket_listen($sock, 5)) {
                    socket_close($sock);
                    return $port;
                }
                socket_close($sock);
            } else {
                return $port;
            }

        } while (++$port <= 65535);

        throw new \UnexpectedValueException('empty port not found');
    }
643595
def port_number(port):
    
    try:
        port = int(port)
    except ValueError:
        raise ValueError("Bad port number")
    if not 0 <= port < 2 ** 16:
        raise ValueError("Bad port number")
    return port
631701
public function setPort($port)
    {
        if ($port != $this->_port) {
            $this->_port = (int)$port;
            $this->_hostInfo = null;
        }
        return $this;
    }
1047376
public function withPort($port): URI
    {
        $result = clone $this;
        $result->port = $this->filterPort($port);

        return $result;
    }
1175014
public function defaultPort($port = null)
    {
        if (!is_null($port)) {
            $this->defaultPort = (int)$port;
            if ($this->url['port'] === null) {
                $this->url['port'] = $this->defaultPort;
            }
        }

        return $this->defaultPort;
    }
512171
public static function port(HTTPRequest $request = null)
    {
        $host = static::host($request);
        return (int)parse_url($host, PHP_URL_PORT) ?: null;
    }
886032
protected function getPort($default = 3000)
    {
        $ports = [];
        foreach ($this->getServerInfo() as $address => $server) {
            $ports[] = $server['port'];
        }

        return PortUtil::getPort($ports ? max($ports) + 1 : $default);
    }