Smack 3.0.4 PacketWriter.java - message data loss on socket error

Hi:

We’re developing an application for devices that have intermittent connectivity. Essentially things are set up like this:

  • messages are written to a local, durable, queue (not smack)

  • a separate thread monitors XMPPConnection.isConnected(), and if connected attempts to send all messages in the queue via the connection, using XMPPConnection.sendPacket()

  • the smack API is configured to auto-reconnect to the remote server (smack API version 3.0.4)

The issue: if the network connection goes down mid-flush, or even between sends (ie: during the writer.flush() on line 274 of PacketWriter.java), we get a javax.net.ssl.SSLException on the stderr console, related to a “Connection reset” java.net.SocketException. The problem is that we have no way to send these messages synchronously, as this exception can never be caught by the client calling XMPPConnection.sendPacket(). Around line 274 of the org.jivesoftware.smack.PacketWriter.java we find the following:

// Flush out the rest of the queue. If the queue is extremely large, it’s possible
// we won’t have time to entirely flush it before the socket is forced closed
// by the shutdown process.
try {
synchronized (writer) {
while (!queue.isEmpty()) {
Packet packet = queue.remove();
writer.write(packet.toXML());
}
writer.flush();
}
}
catch (Exception e) {
e.printStackTrace();
}

// Delete the queue contents (hopefully nothing is left).
queue.clear();

Is this going to be addressed in an upcoming version of the API? I’m referring to the exception block with the e.printStackTrace() and the “hopefully nothing is left” queue.clear() - because something is indeed left and gets discarded in a situation where connectivity is dropped. What would be really nice is a XMPPConnection.sendPacketSynchronous() method (os some such thing) that ensures delivery of the message to the server.

Thanks,

Michael