My team is building an Android application that will use websockets to communicate with an existing backend. We chose to use the AndroidAsync by Koushik Dutta to handle this communication.
I would like to register a ping to be sent periodically, to check if the connection is still alive. I'm using Wireshark to check the network traffic. This is a screenshot of the result that Wireshark is showing:
From what I see here, I believe that the ping is being sent, and the pong is being received.
A snippet of my code is:
private void keepAlive() {
ScheduledExecutorService scheduler =
Executors.newSingleThreadScheduledExecutor();
Runnable runnable = new Runnable() {
public void run() {
Log.d(TAG, "Pinging...");
WebSocketHandler.this.webSocket.ping("LALALA");
}
};
pingScheduledFuture = scheduler.scheduleAtFixedRate(runnable, 0, PING_PERIOD,
TimeUnit.SECONDS);
}
The onPongReceived
method just prints into Logcat
@Override
public void onPongReceived(String s) {
// TODO here I'm aware if connection is still alive
Log.d(TAG, "Pong received! " + s);
}
However, Pong received!
is never printed! Also, if I put a breakpoint there, the app will never stop executing at that point
Anyone has any idea on what may I be missing here?
Best regards and thanks in advance
I'm not familiar with AsyncSocket
but a quick google revealed that you have to register a callback setPongCallback()
somewhere for your pong to be received. Are you doing this? You're not showing a lot of code.