Comments (5)
应用程序关于mqttclient的配置,除了服务器地址,用户名,密码这些必须的外,其它都是默认配置(我是参考例程写的);
from mqttclient.
首先,非常感谢您对这个项目的认可,也非常感谢提出这个测试的问题,
不知道这个issue是否对您有帮助,可以先看看#19
感觉现象有点像,可能是由于网络的原因,导致服务器将客户端主动断开了,
如果是服务端主动发起关闭,此时四次挥手的顺序会颠倒。那么此时客户端再向服务端发送数据时,根据TCP协议的规定,认为它是一个异常终止连接,客户端将会收到一个RST复位响应(而不是ACK响应),如果客户端再次向服务端发送数据,系统将会发送一个SIGPIPE信号给客户端进程,告诉客户端进程该连接已关闭,不要再写了。系统给SIGPIPE信号的默认处理是直接终止收到该信号的进程,所以此时客户端进程会被极不情愿地终止。
如果不希望客户端进程被终止,可以自定义一个该信号处理的函数,通过调用函数signal(SIGPIPE, handler)实现对信号的处理,其中handler就是可以自定义的函数。
所以说当服务端主动关闭,客户端继续写两次将会导致客户端进程被终止(服务端并不能接收),客户端不能向服务器写入数据。
进程会终止,是因为服务器主动close后,客户端还往服务器写数据。
在你的测试代码里面去添加这些测试代码,你就能捕获到异常情况了:
#include <signal.h>
....
void handler(int h)
{
printf("signal handler\n");
}
....
int main(void)
{
....
signal(SIGPIPE, handler);
....
}
....
from mqttclient.
谢谢大咖的回复,根据你的提示,在测试例程中加上signal(SIGPIPE, handler);捕获到异常情况了; 从打印信息来看,此时mqtt_get_client_state状态为仍为CLIENT_STATE_CONNECTED,程序就会进入到这个地方:
` /* mqtt connected, handle mqtt packet */
rc = mqtt_packet_handle(c, &timer);
if (rc >= 0) {
/* scan ack list, destroy ack handler that have timed out or resend them */
mqtt_ack_list_scan(c, 1);`
已经确认mqtt服务端没有做什么特殊配置,基本上都是默认参数;我现在的问题是:接下来怎么处理这种情况,怎样才能重新连上服务器,正常发布消息?
from mqttclient.
我现在的处理方式是,当捕获到该异常情况后,在void handler(int h)函数中增加int mqtt_try_reconnect(mqtt_client_t* c);利用该函数进行重连,但一直打印的信息是:[W] >> ../mqttclient/mqttclient.c:603 mqtt_try_do_reconnect()... mqtt try connect result is -0x0004
from mqttclient.
谢谢大咖的回复;我目前的解决办法,捕获到SIGPIPE信号后, 先释放掉socket连接,然后通过mqtt_set_client_state()设置client状态为:CLIENT_STATE_DISCONNECTED;
` /must realse the socket file descriptor/
network_release(client->mqtt_network);
/* record too much retransmitted data, may be disconnected, need to reconnect */
mqtt_set_client_state(client, CLIENT_STATE_DISCONNECTED);
`
from mqttclient.
Related Issues (20)
- 如何配置 TLS/SSL 以实现仅服务器加密而不进行服务器认证的方式,有实现案例嘛?
- 执行完./build.sh后,在./build/bin目录下没有emqx等执行文件 HOT 1
- 最新源码编译时mqttclient-master/common/log/salof_config.h:12:10: fatal error: mqtt_config.h: No such file or directory HOT 1
- 执行build.sh出现问题 HOT 3
- mqttclient连接上server后,断开网络, mqttclient会尝试重连,每次重连就会出现内存泄漏 HOT 6
- v1.2.0版本和master版本为何删除了test目录?目前执行make-libmqttclient.sh编译会失败 HOT 1
- 怎样增加windows的支持
- 目前有没有1.2.0版本的rt-thread。或者该分支支持rt-thread平台运行吗?
- 请问一下linux下还支持x509证书吗
- tls验证openssl CA证书失败 HOT 3
- ../mqttclient/mqttclient.c:951 mqtt_yield_thread()..., mqtt reconnect timeout....不自动重连的问题
- linux下,mqtt服务器一关闭程序就退出了?
- cleansession=false,无法接受离线消息
- cleansession=false,无法接受离线消息 HOT 1
- 怎么调用mqtt_subscribe使用同一个连接订阅多个主题,应该怎么调整相关代码,调整代码的思路是什么
- 自签名双向认证如何实现? HOT 1
- mqtt5.0
- mqtt_subscribe 缓存已经改成8192, 最大接受数据971个
- platform_net_socket_recv_timeout 区分超时与连接断开
- 枚举变量非对齐访问问题
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mqttclient.