swow icon indicating copy to clipboard operation
swow copied to clipboard

[讨论建议] 通过基于Swow\Socket 实现一个WebSocket 以及 HTTP2 客户端

Open itxiao6 opened this issue 2 years ago • 1 comments

是否可以通过基于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
    {
    }

}

itxiao6 avatar Dec 31 '23 05:12 itxiao6

WebSocket 已经有实现了。http2这个有点复杂

dhermann6 avatar Jan 02 '24 02:01 dhermann6