国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

AsyncTcpConnection客戶端在windows系統(tǒng)下服務(wù)器鏈接斷開沒有觸發(fā)回調(diào)函數(shù)

A文

問題描述

服務(wù):GatewayWorker
客戶端:AsyncTcpConnection
客戶端 向 服務(wù) 發(fā)送數(shù)據(jù),服務(wù)處理數(shù)據(jù)報錯關(guān)閉鏈接,客戶端沒有觸發(fā)onClose回調(diào),連定時器也沒有執(zhí)行,好像是卡著在某段代碼,沒有任何反應(yīng)。

客戶端代碼

worker代碼

$worker = new Worker('tcp://0.0.0.0:1110');
$worker->count = 1;
$worker->name = 'RedisQueue0';
$worker->onWorkerStart = function (Worker $worker) {
    try {
        $protocol = env('SOCKET_PROTOCOL', 'ws');
        $host = env('SOCKET_HOST', '127.0.0.1');
        $port = env('SOCKET_PORT');
        $worker->websocketClient = new WebsocketClient($protocol . '://' . $host . ($port ? ':' . $port : ''));
    } catch (\Throwable $e) {
       echo "客戶端鏈接異常:{$e->getMessage}  in file {$e->getFile()} on line {$e->getLine()}\r\n";
    }
};

AsyncTcpConnection代碼:

use Workerman\Connection\AsyncTcpConnection;
use Workerman\Timer;
class WebsocketClient
{
    /**
     * 連接資源
     * @var AsyncTcpConnection|null
     */
    protected $conn = null;
    /**
     * @var null
     */
    protected $timer = null;
    /**
     * 心跳時間
     * @var null
     */
    protected $heartbeat_time = 30;
    /**
     * 最后一次通訊時間
     * Summary of last_time
     * @var 
     */
    protected $last_time = null;
    /**
     * Summary of remoteAddress
     * @var 
     */
    protected $remoteAddress;
    /**
     * 創(chuàng)捷websocket客戶端連接通訊服務(wù)器
     * Summary of __construct
     * @param mixed $processName
     * @param mixed $remoteAddress
     */
    public function __construct($remoteAddress = 'ws://127.0.0.1:8282')
    {
        $this->remoteAddress = $remoteAddress;
        $this->conn = new AsyncTcpConnection($remoteAddress);
        $this->conn->onConnect = function (AsyncTcpConnection $connection) {
           echo "鏈接成功:{$connection->id}\r\n";
           $this->conn->send(json_encode([
                    'type' => 'data',
                    'data' => [
                        'id'=>1
                    ],
                ]));
           $this->timer = Timer::add($this->heartbeat_time, function () {
                $this->conn->send(json_encode([
                    'type' => 'ping',
                    'data' => 'pong',
                ]));
            });
        };
        $this->conn->onMessage = function (AsyncTcpConnection $connection, $message) {
            echo "接受消息:{$message}\r\n";
        };
        $this->conn->onClose = function (AsyncTcpConnection $connection) {
            echo "鏈接關(guān)閉:{$connection->id}\r\n";
        };
        $this->conn->onError = function (AsyncTcpConnection $connection, $errCode, $errMsg) {
            echo "鏈接錯誤:{$connection->id}--{$errMsg}[{$errCode}]\r\n";
        };
        $this->conn->connect();
    }
}

重現(xiàn)問題的步驟

第一步:啟動GatewayWorker服務(wù);
第二步:啟動客戶端,客戶端使用AsyncTcpConnection鏈接服務(wù),成功后向服務(wù)發(fā)送數(shù)據(jù);
第三步:服務(wù)處理接受數(shù)據(jù),數(shù)據(jù)處理異常導(dǎo)致鏈接關(guān)閉

操作系統(tǒng)環(huán)境及workerman/webman等具體版本

系統(tǒng):Windows 11 專業(yè)版
截圖

548 0 0
0個回答

??