diff --git a/src/Server.php b/src/Server.php index 2d7efac..a954ee0 100644 --- a/src/Server.php +++ b/src/Server.php @@ -115,7 +115,15 @@ class Server { */ 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);