powered by Jive Software

Add method to send SM acks unrequested/unconditionally to the server

According to XEP-0198:

“Either party MAY send an element at any time (e.g., after it has received a certain number of stanzas, or after a certain period of time), even if it has not received an element from the other party.”

I can’t seem to find a method to send an unrequested ack in Smack 4.1-alpha4, is this feature planned?

1 Like

No it’s not planed, but wouldn’t be hard to add. May I ask the use case?

I see 2 possible use cases:

  1. acknowledging all stanzas received before graceful disconnection
  2. periodically acknowledging messages received
  1. can be achieved by using the ForEveryStanza predicate at XMPPTCPConnection (SMACK-NIGHTLY-JOB1 4.1.0-alpha5-SNAPSHOT API)

What’s the use case for 2? If you don’t set a predicate, Smack will automatically request an ack if the unacked stanza queue reaches a certain threshold.

  1. How can it be achieved with ForEveryStanza? I still need a way to send the unrequested ack

  2. Sometimes there is not enough packets to pass the threshold but time passes and we want to update the server on the received packets(so in case of network failure/unexpected crash we will have a more updated state)

1 Like

I’m sorry I confused the acks. We are talking about the Client (Smack) to send an ack without preceding request. The predicates are only for client requests that (should) result in a server ack.

You made me notice that it may be a good idea to send a ack when the client tries to cleanly terminate the connection. Also I’ll add a method to send an Ack unconditionally.


Hi Flow,

I stumbled upon this post by coincidence. I also need the feature of sending an ack unconditionally. Do you have a rough estimation of when should it be ready (maybe next alpha version)?

Also, is there a plan for when Smack 4.1 will be released (not alpha)?

Out Of curiosity: Why do you need that?

I don’t want to rely on either party (clients or server) to count messages before an ack is sent. I want an ack to be sent always, on each message received, in any XMPP entity (client or server), to assure maximum reliability (don’t care about network traffic since it’s going to be for a small group of users anyhow). I hope I answered your question.

That sounds like Smack’s XMPPTCPConnection should get a addSendAckPredicate() method.

After thinking a bit more about, I decided against adding such a method, as it would become basically a packet listener that when triggered calls sendSmAcknowledgement(). This is something the user an do itself.

Added with Add XMPPTCPConnection.sendSMAcknowledgement · 65ccec9 · igniterealtime/Smack · GitHub


Hey Flow,

XMPPTCPConnection.sendSMAcknowledgement is enough for all my needs,

however I think it contains a race condition over clientHandledStanzasCount(reading it may not be atomic).

however I think it contains a race condition over clientHandledStanzasCount(reading it may not be atomic).

I don’t believe so, since we only use the lower 32bit of the long. See also javadoc of clientHandledStanzaCount: https://github.com/igniterealtime/Smack/blob/6b21455b32301d13996775c25879381faea 0bd2a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java# L222

Right, sorry about that