关于mqtt连接报错

萌萌哒

问题描述

做异步消息转发的时候,使用mqtt,连接一段时候,就会出现报错,这改如何解决?

程序代码

$asyCon = new AsyncTcpConnection('ws://ws.xxx.com');

$asyCon->onConnect = function(AsyncTcpConnection $asyCon){
    $asyCon->send(json_encode(['action' => 'test','params' => 'test']));
};

$asyCon->onMessage = function (AsyncTcpConnection $con, $data){
    $mqtt = new Workerman\Mqtt\Client('mqtt://127.0.0.1:1883');

    $mqtt->onConnect = function($mqtt) use($data) {
        $mqtt->publish('resData', $data);
    };

    $mqtt->onError = function ($data) use ($con){
        echo $data->getMessage().":".$data->getCode().PHP_EOL;
    };

    $mqtt->connect();
};

报错信息

Connection timeout 101

626 0 0
0个回答

×
🔝