Git Product home page Git Product logo

Comments (4)

jiejieTop avatar jiejieTop commented on July 20, 2024 1

后来发现是emqx退出时发送了清除client命令,mqttclient线程在处理这个命令的时候线程就直接退出了,同理手动剔除这个客户端也会导致退出

发送了clean肯定会退出吧,如果这都不退出,那岂不是乱套了吗,否则就会导致我手动clean都干不掉这个客户端了

from mqttclient.

jiejieTop avatar jiejieTop commented on July 20, 2024

还没有测试过这种情况哦,理论上貌似不会退出吧.

from mqttclient.

luqinlive avatar luqinlive commented on July 20, 2024

后来发现是emqx退出时发送了清除client命令,mqttclient线程在处理这个命令的时候线程就直接退出了,同理手动剔除这个客户端也会导致退出

from mqttclient.

jiejieTop avatar jiejieTop commented on July 20, 2024

对于这个问题,我已经查阅到相关的资料了,不是mqtt本身的问题,而是socket的问题,欢迎联系我交流,微信:1161959934

如果是服务端主动发起关闭,此时四次挥手的顺序会颠倒。那么此时客户端再向服务端发送数据时,根据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.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.