ekstazi/websocket-common-amphp

适用于流接口的amphp/websocket适配器实现

2.1.1 2020-04-10 12:26 UTC

This package is auto-updated.

Last update: 2024-09-10 22:28:09 UTC


README

ekstazi/websocket-common-amphpamphp/websocket 适配器,用于amphp流。此包在 ekstazi/websocket-stream-client-amphp 中内部使用

安装

此包可以作为Composer依赖项安装。

composer require ekstazi/websocket-common-amphp

要求

PHP 7.2+

使用

<?php

use ekstazi\websocket\common\amphp\Reader;
use ekstazi\websocket\common\amphp\Connection;
use ekstazi\websocket\common\amphp\Writer;

/** @var \Amp\Websocket\Client $client */
$stream = new Connection(new Reader($client), new Writer($client));
$stream->setDefaultMode(Writer::MODE_TEXT);
// alternative way to create stream
// $stream = Connection::create($client, Writer::MODE_TEXT);
yield $stream->read();
yield $stream->write('test');