Smack 4.1.x upgrade Guide
I. Major improvements to Smack 4.1
Smack 4.1.x has two major improvements:
1) Support XEP-198 specifications, that is, stream management
2) native support for Android
Smack 4.1 allows the original aSmack database to be dumped into the garbage. Note that the latest version of aSmack is only 4.0.7.
Ii. Stream Management
Stream Management)
Smack 4.1 is disabled by default for stream management. You can enable Stream Management in the following ways:
XMPPTCPConnection. setUseStreamManagement (true)
Flow Management specifications available: http://xmpp.org/extensions/xep-0198.html
Stream Management is an extension of XMPP. It adds Acknowledgement and stream recovery. This means that if you use Jabber on your mobile phone, messages will not be lost even if they are not in the service area.
Jaber uses the TCP protocol, which is a reliable protocol. When a user loses a connection, the message may be lost. At this time, the service area still maintains a TCP connection to the client to send messages, when the client leaves the service area, the message may be lost.
In good cases, when the client leaves the service area, the Network Provider immediately closes the connection. In this way, the message will be saved as an offline message to the server. In some bad cases, when the client leaves the l service area, and the server connection is not broken, the server forwards the message to the client, and the message will be lost.
The XEP-198 specification is a solution to this situation. It does not allow clients to stay connected offline, but introduces two important elements, the client can retrieve the message after it misses the message.
The validation section allows the server and client to confirm each request sent for a single message or group message. Once a confirmation is received, the message is considered successfully delivered.
Stream recovery is used when the connection is rebuilt. By including the serial number in the validation section, both the client and server can know when the message was interrupted and send the message again.
These two mechanisms can provide reliable guarantee for each delivered message, and the same mechanism can also be used for S2S (server connection server ).
Iii. Smack 4.1 API changes
Major API changes for Smack 4.1.x include:
Change XMPPConnection to interface
When declaring a connection, you can use the class of AbstractXMPPConnection or XMPPConnection as the static type.
SASL authentication is implemented again
For the custom SASL mechanism, you may need to adjust the code.
Added the IQ request handle API
Packet listeners and Packet collectors can no longer listen to IQ requests, that is, IQ's "get" and "set" types.
XMPPConnection. addPacketListener method discarded
Instead, use the addAsyncPacketListener method to add the asynchronous packet listener or the addSyncPacketListener method to replace it.
StringUtils tool class
The StringUtils tool class is added to the XmppStringUtils package (in the jxmpp-core Package). The method name also changes, for example, parseName is changed to parseLocalpart.
Changes in the message listener class
The MessageListener class of the message listener is changed to ChatMessageListener. The MessageListener class name cannot be used.
The connection configuration class uses the Builder mode.
The connection configuration ConnectionConfiguration class uses the Builder design mode.
FormField. getType and Form. getType
Both FormField. getType and Form. getType are changed to Enum of Enumeration type.
Packet interface discarded
The Packet interface is discarded. Use the getStanzaId method of the new Stanza class to replace the getPacketID method.
Roster Class Changes
Use Roster. instance to obtain an instance, which was originally obtained by the XMPPConnection. getRoster method.
ConnectionListener. authenticated method changes
The ConnectionListener. authenticated method adds a Boolean parameter resumed.
The XMPPTCPConnection. addStanzaAcknowledgedListener method cancels an exception.
The XMPPTCPConnection. addStanzaAcknowledgedListener method cancels the StreamManagementNotEnabledException exception.
If SASL extension is used, use ConnectionConfiguration. Builder. allowEmptyOrNullUsernames
SmackConfiguration. DEBUG_ENABLED changed to SmackConfiguration. DEBUG
This article permanently updates the link address: