Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to close the connection from Client to Broker

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to close the connection between Client and Broker. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Let's take a look at how to close the connection from Client to Broker.

Client actively closes the connection

The process for Client to actively close the connection is very simple, as long as a DISCONNECT packet is sent to Broker. DISCONNECT packets do not have variable headers (Variable header) and message bodies (Payload). After Client sends the DISCONNECT, you can close the underlying TCP connection without waiting for a reply from Broker (Broker doesn't reply to DISCONNECT packets either).

Here the reader may wonder why it is necessary to send a DISCONNECT packet that does not interact with the Broker before closing the TCP connection, rather than directly closing the underlying TCP connection.

A feature of the MQTT protocol is involved here. Broker needs to determine whether the Client is disconnected properly.

When Broker receives a DISCONNECT packet from Client, it assumes that Client is normally disconnected, then it discards the last wish message (Will Message) specified by the current connection. If Broker detects a loss of Client connection but does not receive a DISCONNECT message packet, it will assume that Client is abnormally disconnected and will issue a will message (Will Message) to the Will Topic specified at the time of connection.

Broker actively closes the connection

MQTT protocol stipulates that Broker should maintain a connection with Client before receiving DISCONNECT packets from Client. Only Broker will actively close the connection when it does not receive any MQTT packets from Client during the time interval of Keep Alive. Some Broker implementations extend the MQTT protocol to support Client connection management and can actively disconnect from a Client.

The above is how to close the connection between Client and Broker. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report