使用mqtt连接服务端mqtt的ws协议

null

问题描述

服务端用mqtt用的ws协议,服务端发CONNET包服务端未返回CONNACK包,用mqtt协议能正常使用

<?php

namespace app\socket\controller;

use app\common\model\Bracelet as BraceletModel;
use think\worker\Server;
use Workerman\Mqtt\Client;

class Bracelet extends Server
{
    protected $socket = 'tcp://0.0.0.0:8000';

    protected $option = [
        'name' => 'Bracelet server',
    ];

    public function onConnect($connection){

    }

    public function onWorkerStart()
    {
        $options = [
            'clean_session' => false,
            'debug' => true,
        ];
        $mqtt = new Client('ws://192.168.31.214:9001',$options);
        $mqtt->onConnect = function($mqtt) {
            $mqtt->subscribe('OPEN_PERSON_INFO',['qos' => 2]);
        };
        $mqtt->onMessage = function($topic, $content){
            $info = json_decode($content,true);

            BraceletModel::create($info);
        };
        $mqtt->connect();
    }

    public function onMessage($connection, $data)
    {

    }

    public function onClose($connection)
    {

    }
}

截图

2210 1 0
1个回答

xiuwang

Workerman\Mqtt\Client 不支持ws

  • 暂无评论
年代过于久远,无法发表回答
×
🔝