simple-swoole / simps

🚀 A simple, lightweight and high-performance PHP coroutine framework.
https://simps.io
Apache License 2.0
469 stars 48 forks source link

mqtt服务如何使用和启动? #38

Closed gzqy closed 4 months ago

gzqy commented 4 months ago

我搭建了一个mqtt服务,显示mqtt运行。 创建了mqttserver, 粘贴服务端代码。 但是无法连接使用。

gzqy commented 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'],
            ]
        )
        );

    }