NaikSoftware / StompProtocolAndroid

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

heart-beat header #18

Open dimonik opened 7 years ago

dimonik commented 7 years ago

Does your library support heart-beat mechanism?

According to spec:

The heart-beat header is OPTIONAL. A missing heart-beat header MUST be treated the same way as a “heart-beat:0,0” header, that is: the party cannot send and does not want to receive heart-beats.

NaikSoftware commented 7 years ago

no.. always send 0,0

1 нояб. 2016 г. 1:47 ПП пользователь "dimonik" notifications@github.com написал:

Does your library support heart-beat mechanism?

According to spec:

The heart-beat header is OPTIONAL. A missing heart-beat header MUST be treated the same way as a “heart-beat:0,0” header, that is: the party cannot send and does not want to receive heart-beats.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/NaikSoftware/StompProtocolAndroid/issues/18, or mute the thread https://github.com/notifications/unsubscribe-auth/AEBgch-94iF1zJjokDsVp7sbAFrZtnGqks5q5ya1gaJpZM4KmAuh .

ghost commented 7 years ago

Does this library supports ping pong feature because the connection is no more alive after fer minutes

steviemo commented 7 years ago

Yes we are seeing this too - the stomp client closes after around 1 min. Is there a workaround for this? We are using spring as websocket server. If I use the Java-WebSocket class to create the websocket the stomp connection closes cleanly, however if we use okhttp the stomp client throws an error after 1 min of inactivity - Stomp connection error java.lang.Exception: java.io.EOFException at ua.naiksoftware.stomp.OkHttpConnectionProvider$1.onFailure(OkHttpConnectionProvider.java:107) at okhttp3.internal.ws.RealWebSocket.failWebSocket(RealWebSocket.java:543)

For out web client we use stomp.js (connecting) to same server and don't have any of these issues. I think a heart beat thread needs to be implemented with this library - I'll have a look next week

steviemo commented 7 years ago

OK turns out the STOMP client is being closed due to ELB - not by our spring server. A direct connection to our spring server using this client maintains a connection. I think the ELB is closing as connection is idle and this doesn't happen with using stomp.js as it has a heart beat so keeps the WS connection active.

I'll look at implementing a heartbeat for this library that can be enabled/disabled and will submit a pull request

steviemo commented 7 years ago

For other that might use this thread I was able to implement my own heart beat thread which starts in the OPENED lifecycle event and stops on ERROR or CLOSED:

private void startHeartbeat() { heartbeat = heartbeatExecutor.scheduleAtFixedRate(new Runnable() { @Override public void run() { Log.e(TAG, "SEND HEARTBEAT FROM SERVICE"); if (null != stompClient) { stompClient.send("", "h").subscribe(); } } }, 0, 25, TimeUnit.SECONDS); } private void stopHeartbeat() { if (null != heartbeat) { heartbeat.cancel(true); heartbeat = null; } }