Heartbeat Detection in the ANDROIDPN

Source: Internet
Author: User

There is a heartbeat detection function in the ANDROIDPN client. Is that every once in a while the client sends a message to the server to detect if the connection is normal, and the message is sent as follows:

<presence id= "H09KE-13" ></presence>

Heartbeat detection frequency time is set in the Smackconfiguration class:


Heartbeat detection tasks are defined and opened in the Packetwriter class:

Process of heartbeat detection:

1. The heartbeat packet is sent to the service at the time of Heartbeat;

2. If the sending fails, throw the failed exception;

3. This anomaly will be captured by the Connectionclosedonerror method of the Persistentconnectionlistener listener, and the parameter of this method is a exception object;

4. In the Connectionclosedonerror method, the last connection object is disconnected, and then the Reconnectionthread thread is started to reconnect to the server;

5. If the connection fails again, the waiting parameter will be increased by one, reconnectionthread the next time interval to connect the server, the role is to control the client when the server is not open when the server does not connect frequently,

So the client does not do a lot of useless work;

The above is the code of their own tracking understanding, if there is no understanding of the place please correct me, thank you.

Reference:

http://blog.csdn.net/majian_1987/article/details/9856127

Heartbeat Detection in the ANDROIDPN

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.