ekstazi / websocket-server-adapter
基于不同实现的Amp异步WebSocket服务器适配器。
1.0
2020-04-10 14:58 UTC
Requires
- php: >=7.2
- ext-pcntl: *
- amphp/amp: ^2.2
- amphp/byte-stream: ^1
- psr/log: ^1.1
Requires (Dev)
- amphp/php-cs-fixer-config: dev-master
- amphp/phpunit-util: ^1.1
- phpunit/phpunit: ^8 || ^7
Suggests
- ekstazi/websocket-server-adapter-amphp: For amphp websocket-server implementation
- ekstazi/websocket-server-adapter-implementation: For websocket server implementation
This package is auto-updated.
Last update: 2024-09-11 01:12:30 UTC
README
WebSocket服务器是一组接口,为amphp提供WebSocket服务器。
安装
此包可以作为Composer依赖项安装。
composer require ekstazi/websocket-server-adapter
要求
PHP 7.2+
接口
提供的接口
interface ServerFactory
方法
create(Amp\Socket\Server $socket, LoggerInterface $logger = null): Server
返回服务器类实例
interface Server
方法
public function addRoute(string $path, Handler $handler): void;
向指定路由添加处理器。
public function run(): void;
运行主事件循环并订阅SIGINT/SIGTERM信号。
public function stop(): Promise
停止服务器并完成事件循环
interface Handler
方法
public function onHandshake(ConnectionInfo $connectionInfo): Promise;
在握手协商之后、WebSocket升级之前被调用。您可以在此处验证您的连接
public function handle(Connection $connection): Promise;
在升级完成后调用此方法。
public function getSubProtocols(): array;
支持的子协议列表。如果客户端不支持其中之一,则连接不会启动
interface ConnectionInfo
方法
public function getId(): string;
获取连接ID
public function getArgs(): array;
获取传递给连接的参数
public function getRemoteAddress(): string;
获取客户端的远程地址
interface Connection extends ConnectionInterface, ConnectionInfo
更多详细信息请参阅 ekstazi/websocket-common