1

Hi all I have to create an application that needs to stay connected as much as possible to a websocket server to listen for events. Since its a security app, resources such as battery and radio usage is not a concern.

I am using standard org.java_websocket with the Draft_17 spec. The application is able to communicate using websockets. The issue is that when the phone loses connection to the server. It takes a few min for the websocket to realise that it's disconnected before calling the onClose() callback with a code 1006. I need to reduce this time as much as possible. When using HTTP clients on android this is no issue, we just simply set the socket timeout. However using org.java_websocket I am unable to figure out how to set this timeout.

I am constantly sending/receiving data from the server. Sending does not speed up the socket timeout in any way.

There is a connection timeout parameter on the WebSocket constructor.

return new WebSocketClient(hostURI, new Draft_17(), null, 5000)

But it has no effect as I think this is only when trying to connect to the server initially.

Any help or guidance will be appreciated

asked Apr 6, 2016 at 17:10
3
  • did you find any fix for this ? Commented Nov 30, 2016 at 10:31
  • @patric Not really. I ended up sending a byte of data to the client every 3 seconds then having a timer on the Android app set to run every 3 seconds. When I receive the byte then I set a flag to true. If my timer fires then I set it to false. the moment it sets it to false twice in a row then I ignore the old connection and start a new one. Works well since its in production already. Commented Nov 30, 2016 at 13:00
  • Thanks for reply am also working on similar kind of work around. Thanks. Commented Dec 2, 2016 at 7:42

1 Answer 1

1

If you check the WebSocketClient source code, you will notify that the timeout parameter is never used

answered Jan 5, 2017 at 7:59
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.