hhxsv5 / laravel-s

LaravelS is an out-of-the-box adapter between Laravel/Lumen and Swoole.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TCP 连接不能在控制器推送

ykxiao opened this issue · comments

  1. Your software version (Screenshot of your startup)

    Software Version
    PHP 8.0.26
    Swoole 5.0.1
    Laravel/Lumen 8.83.26
  2. Detail description about this issue(error/log)

    1: ✘ ykxiao@ip-192-168-43-20  ~  telnet 127.0.0.1 5291
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    Welcome to cusService.
    2:监听TCP后,在控制器推送消息时提示:"Swoole\WebSocket\Server::push(): the connected client of connection[2] is not a websocket client or closed"

  3. Some reproducible code blocks and steps

    use Swoole\WebSocket\Server;
    /**
     * @return JsonResponse
     */
    public function tcpTest(): JsonResponse
    {
        /**@var \Swoole\Http\Server|Server $swoole */
        $swoole = app('swoole');
        $port = $swoole->ports[1];
        foreach ($port->connections as $fd) {
            if ($swoole->isEstablished($fd)) {
                $swoole->push($fd, 'Send TCP message');
            }
        }
        return $this->response->success();
    }

发TCP消息用send(),isEstablished()和push()是针对WebSocket的。
// $swoole->send($fd, 'Send tcp message');

好的,了解