How to disable the built-in PingManager

I am wondering how I can disable the built-in PingManager. It seems that it is automatically added to the connection and replaces my IQRequestHandler implementation that I register on the connection before performing the connect.

Coming from smack 3.4.x I have a currently well working solution that checks the incoming ping stanzas from the server and replies to it. My current implementation considers the connection dead if it has not received any ping for a while. I do not want to perform additional pings from the client to the server. Nor I want to have an additional thread pool per connection just to perform this ping handling.

You can use SmackConfiguration.addDisabledSmackClass(), or you can register a custom IQ request handler for pings, replacing the existing one.

But the server really shouldn’t ping the client. It’s the client that should ping the server in order to determine the aliveness of the connection. That is because only the client can decide when it’s a good time to ping (e.g. in order to conserve battery).

Thanks… The first approach worked. I’ve initially tried to register my own IQ handler but I think the problem here is that the PingManager registers itself as ConnectionCreationListener and add’s itself as IQ handler for the ping. In my tests my custom handler was overridden and was never called.

Hmm? How could the custom handler got overriden by PingManager if there is no way to add the custom handler before the PingManger adds its handler?

I instantiated a XMPPTCPConnection object and registered my IQ handler on it (registerIQRequestHandler).

Then, when performing the connect() operation on the connection, the PingManager registers its handler in the ConnectionCreationListener. Since the element and namespace is the same for the incoming ping IQ messages, the my IQ handler is overridden in the getIqRequestHandler Map (AbstractXMPPConnection).

Ahh right. I forgot that this is how it’s done in the 4.1 branch. This has been changed in 4.2 and should be no longer an issue in Smack 4.2: Smack/ at 3bbffeae285d2467d8829d3e9f63fd7d7de11dd4 · igniterealtime/Smack · GitHub

As workaround in 4.1 you could instantiate the PingManager before registering your custom handler. E.g.

XMPPTCPConnection connection = new XMPPTCPConnection(…);