首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
MQTT 添加配置后,无响应,这是为什么?
### 问题描述 终端运行:telnet 127.0.0.1 9501 无响应 [root@VM_0_8_centos ~]# telnet 127.0.0.1 9501 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. 222 ### 相关代码 ```php //多进程管理模块 $pool = new Swoole\Process\Pool(2); //让每个OnWorkerStart回调都自动创建一个协程 $pool->set(['enable_coroutine' => true, 'open_mqtt_protocol' => true]); $pool->on("workerStart", function ($pool, $id) { //每个进程都监听9501端口 $server = new Swoole\Coroutine\Server('127.0.0.1', '9501' , false, true); //收到15信号关闭服务 Swoole\Process::signal(SIGTERM, function () use ($server) { $server->shutdown(); }); //接收到新的连接请求 $server->handle(function (Swoole\Coroutine\Server\Connection $conn) { //接收数据 $data = $conn->recv(); if (empty($data)) { //关闭连接 $conn->close(); } //发送数据 $conn->send("hellooooooo"); }); //开始监听端口 $server->start(); }); $pool->start(); ```
发布于6年前 · 1 次浏览 · 来自
提问
栀沫@
### 问题描述 终端运行:telnet 127.0.0.1 9501 无响应 [root@VM_0_8_centos ~]# telnet 127.0.0.1 9501 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. 222 ### 相关代码 ```php //多进程管理模块 $pool = new Swoole\Process\Pool(2); //让每个OnWorkerStart回调都自动创建一个协程 $pool->set(['enable_coroutine' => true, 'open_mqtt_protocol' => true]); $pool->on("workerStart", function ($pool, $id) { //每个进程都监听9501端口 $server = new Swoole\Coroutine\Server('127.0.0.1', '9501' , false, true); //收到15信号关闭服务 Swoole\Process::signal(SIGTERM, function () use ($server) { $server->shutdown(); }); //接收到新的连接请求 $server->handle(function (Swoole\Coroutine\Server\Connection $conn) { //接收数据 $data = $conn->recv(); if (empty($data)) { //关闭连接 $conn->close(); } //发送数据 $conn->send("hellooooooo"); }); //开始监听端口 $server->start(); }); $pool->start(); ```
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
2020-03-27
郭新华
你这只是telnet tcp连上去了,发送的是原始的tcp数据流,不是mqtt协议的数据啊
赞
0
回复