diff --git a/src/Client.php b/src/Client.php index 4c89568..9a8b78d 100644 --- a/src/Client.php +++ b/src/Client.php @@ -35,9 +35,8 @@ namespace Ripple\WebSocket; use Closure; -use Co\IO; use Exception; -use Ripple\Socket\SocketStream; +use Ripple\Socket; use Ripple\Stream; use Ripple\Stream\Exception\ConnectionException; use Ripple\Utils\Output; @@ -92,9 +91,9 @@ class Client private Closure $onError; /** - * @var SocketStream + * @var Socket */ - private SocketStream $stream; + private Socket $stream; /** * @var string @@ -161,8 +160,8 @@ private function handshake(): void $path = $parsedUrl['path'] ?? ''; $path = $path !== '' ? $path : '/'; $this->stream = match ($scheme) { - 'ws' => IO::Socket()->connect("tcp://{$host}:{$port}", $this->timeout, $this->context), - 'wss' => IO::Socket()->connectWithSSL("ssl://{$host}:{$port}", $this->timeout, $this->context), + 'ws' => Socket::connect("tcp://{$host}:{$port}", $this->timeout, $this->context), + 'wss' => Socket::connectWithSSL("ssl://{$host}:{$port}", $this->timeout, $this->context), default => throw new Exception('Unsupported scheme'), }; diff --git a/src/Server.php b/src/Server.php index 1a4355f..3d96512 100644 --- a/src/Server.php +++ b/src/Server.php @@ -35,9 +35,8 @@ namespace Ripple\WebSocket; use Closure; -use Co\IO; use Ripple\Kernel; -use Ripple\Socket\SocketStream; +use Ripple\Socket; use Ripple\Stream\Exception\RuntimeException; use Ripple\WebSocket\Server\Connection; use Symfony\Component\HttpFoundation\Request; @@ -71,8 +70,8 @@ class Server /*** @var Closure */ private Closure $onRequest; - /*** @var SocketStream */ - private SocketStream $server; + /*** @var Socket */ + private Socket $server; /*** @var Options */ private Options $options; @@ -104,7 +103,7 @@ public function __construct(string $address, mixed $context = null, Options|null throw new RuntimeException('The address must contain a port'); } - $this->server = IO::Socket()->server("tcp://{$host}:{$port}", $context); + $this->server = Socket::server("tcp://{$host}:{$port}", $context); $this->server->setOption(SOL_SOCKET, SO_KEEPALIVE, 1); $this->server->setOption(SOL_SOCKET, SO_REUSEADDR, 1); @@ -121,7 +120,7 @@ public function __construct(string $address, mixed $context = null, Options|null */ public function listen(): void { - $this->server->onReadable(function (SocketStream $stream) { + $this->server->onReadable(function (Socket $stream) { try { if (!$client = $stream->accept()) { return; diff --git a/src/Server/Connection.php b/src/Server/Connection.php index 9d06af6..1fe67ef 100644 --- a/src/Server/Connection.php +++ b/src/Server/Connection.php @@ -35,7 +35,7 @@ namespace Ripple\WebSocket\Server; use Closure; -use Ripple\Socket\SocketStream; +use Ripple\Socket; use Ripple\Stream\Exception\ConnectionException; use Ripple\Utils\Output; use Ripple\WebSocket\Frame\Type; @@ -119,12 +119,12 @@ class Connection private Closure|null $onRequest = null; /** - * @param SocketStream $stream + * @param Socket $stream * @param Server $server */ - public function __construct(public readonly SocketStream $stream, private readonly Server $server) + public function __construct(public readonly Socket $stream, private readonly Server $server) { - $this->stream->onReadable(fn (SocketStream $stream) => $this->handleRead($stream)); + $this->stream->onReadable(fn (Socket $stream) => $this->handleRead($stream)); $this->stream->onClose(fn () => $this->_onClose()); } @@ -132,11 +132,11 @@ public function __construct(public readonly SocketStream $stream, private readon * @Author cclilshy * @Date 2024/8/15 14:44 * - * @param SocketStream $stream + * @param Socket $stream * * @return void */ - private function handleRead(SocketStream $stream): void + private function handleRead(Socket $stream): void { try { $data = $stream->readContinuously(1024);