Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
add ipv6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost committed Jan 25, 2024
1 parent ae72a00 commit 6be1b4f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,15 @@ public function setKey(string $key): self
*/
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);

Expand Down

0 comments on commit 6be1b4f

Please sign in to comment.