Closed gzqy closed 4 months ago
1.配置服务启动, 2.mqtt连接版本选3.1, 3.自定义方法使用 $server->send中的 MQTT::getAck方法对应具体的服务器操作。
public function onMqSubscribe($server, int $fd, $fromId, $data)
{
var_dump('订阅:' . json_encode($data));
$server->send($fd, MQTT::getAck(
[
'cmd' => 8, // CONNACK固定值为2
'code' => 0, // 连接返回码 0表示连接已被服务端接受
'session_present' => 0,
'message_id'=>$data['message_id'],
'topics'=>$data['topics'],
]
)
);
}
我搭建了一个mqtt服务,显示mqtt运行。 创建了mqttserver, 粘贴服务端代码。 但是无法连接使用。