<?php
use Workerman\Worker;
require_once __DIR__ . '/Workerman/Autoloader.php';
$worker = new Worker();
$worker->onWorkerStart = function(){
$mqtt = new Workerman\Mqtt\Client('mqtt://ip:1883');
$mqtt->onConnect = function($mqtt) {
$mqtt->subscribe('test');
};
$mqtt->onMessage = function($topic, $content){
var_dump($topic, $content);
};
$mqtt->connect();
};
Worker::runAll();
我测试这个代码,链接自己服务器搭建的emq。就是mqtt5.0。发现无法通信。请教大家解决方案。
只能mqtt转给websocket