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