hhxsv5 / laravel-s

LaravelS is an out-of-the-box adapter between Laravel/Lumen and Swoole.
MIT License
3.82k stars 470 forks source link

TCP 连接不能在控制器推送 #428

Closed ykxiao closed 1 year ago

ykxiao commented 1 year ago
  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();
    }
hhxsv5 commented 1 year ago

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

ykxiao commented 1 year ago

好的,了解