NaikSoftware / StompProtocolAndroid

STOMP protocol via WebSocket for Android
MIT License
597 stars 265 forks source link

add heart-beat support to avoid time out disconnect #88

Closed 1037390459 closed 5 years ago

forresthopkinsa commented 6 years ago

Hey, make an issue on the downstream explaining what you want with as much detail as you can manage, and we'll start looking into our options for making this work well.

luisalves00 commented 5 years ago

I'm adding heart-beat support. Will you accept a pull request and do a new release?

NaikSoftware commented 5 years ago

Yes of course

jdupont22 commented 5 years ago

Hi,

I've found a trick to avoid server timeout disconnect on missing pong reply on ping frame from the server. Only work with "Stomp.ConnectionProvider.OKHTTP" and the server heartbeat set. mStompClient.setHeartbeat(30*1000);

I've modified the class "OkHttpConnectionProvider" on line 67, when the heartbeat from server is received, like this:

@Override public void onMessage(WebSocket webSocket, String text) { if (text.equals("\n")) { Log.d(TAG, "RECEIVED HEARTBEAT"); rawSend("\n"); } else emitMessage(text); } On each heartbeat from the server, i respond with a raw frame "\n".

Work with RabbitMq and WebStomp plugin.

luisalves00 commented 5 years ago

@jdupont22 nice trick :) usually the server and client heart-beat are set to same value.

luisalves00 commented 5 years ago

Just waiting for your review and/or merge.