Browse Source

add ipv6 support

main
ghost 10 months ago
parent
commit
6be1b4fe2c
  1. 10
      src/Server.php

10
src/Server.php

@ -115,7 +115,15 @@ class Server {
*/ */
protected function openSocket(string $ip, int $port): bool protected function openSocket(string $ip, int $port): bool
{ {
$addr = "tcp://" . $ip . ':' . $port; if (false !== filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
{
$addr = 'tcp://[' . $ip . ']:' . $port;
}
else
{
$addr = 'tcp://' . $ip . ':' . $port;
}
$this->socket = stream_socket_server($addr, $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $this->context); $this->socket = stream_socket_server($addr, $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $this->context);

Loading…
Cancel
Save