1

I'm using autobahn android web socket library to build my web socket client application. In order to keep the web socket connection alive for a long time, I need to periodically send ping messages from the client.

How can I do that with auotbahn android web socket library?

2 Answers 2

0

AutobahnAndroid's WebSocketWriter supports client pong messages, and AutobahnPython claims the following:

explicit processing of Pings/Pongs is unnecessary normally - AutobahnPython will do the right thing under the hood.

However, during execution of a simple chat client-server setup, I observe no such ping/pong heartbeat messages.

From what I have read, it is unclear from both the documentation and the source, what the full requirements are for enabling implicit Autobahn* heartbeats.

My personal solution involves issuing a ping from the server during onConnection and the appropriate onMesssage, and something similar to the following client code onMessage:

if (payload.equals("ping from the server"))) {
    handler.postDelayed(new Runnable() {
        @Override
            public void run() {
                myWebSocket.sendTextMessage("pong from the client");
            }
    }, 1000L);
}

... which schedules a pong response to be sent by the client, 1 second after receiving a ping from the server.

0

You can use the pull request that I just submitted

https://github.com/tavendo/AutobahnAndroid/pull/67

which adds sendPingMessage(byte[] payload) and onPongMessage(byte[] payl).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.