swow
swow copied to clipboard
[讨论建议] 通过基于Swow\Socket 实现一个WebSocket 以及 HTTP2 客户端
是否可以通过基于Swow\Socket 实现一个WebSocket 以及 HTTP2 客户端
如下示例
WebSocket Client
<?php
declare(strict_types=1);
namespace Swow\Client;
use Psr\Http\Message\UriInterface;
use Swow\Psr7\Message\WebSocketFrameInterface;
/**
* Class WebSocket
* @package Swow\Client
*/
class WebSocket
{
/**
* WebSocket constructor.
* @param UriInterface $uri
* @param array $options Headers 以及 SSL证书相关配置
*/
public function __construct(UriInterface $uri, array $options = [])
{
}
/**
* 接收消息
* @param int $timeout
* @return WebSocketFrameInterface
*/
public function receive(int $timeout = -1): WebSocketFrameInterface
{
}
/**
* 发送数据到服务
* @param $data
* @return bool
*/
public function send($data): bool
{
}
/**
* 关闭连接
* @return bool
*/
public function close(): bool
{
}
}
HTTP2 Client
<?php
declare(strict_types=1);
namespace Swow\Client;
use Psr\Http\Message\UriInterface;
use Psr\Http\Message\MessageInterface;
/**
* Class HTTP2
* @package Swow\Client
*/
class HTTP2
{
/**
* WebSocket constructor.
* @param UriInterface $uri
* @param array $options Headers 以及 SSL证书相关配置
*/
public function __construct(UriInterface $uri, array $options = [])
{
}
/**
* 接收消息
* @param int $timeout
* @return MessageInterface
*/
public function receive(int $timeout = -1): MessageInterface
{
}
/**
* 关闭连接
* @return bool
*/
public function close(): bool
{
}
}
WebSocket 已经有实现了。http2这个有点复杂