服务端用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)
{
}
}
Workerman\Mqtt\Client 不支持ws