How to differentiate between Internet disconnection and WebSocket server down using websocket client

Currently we are getting websocket connection lost either it’s Internet disconnection or WebSocket server down/unreachable. Is there any way to get specific reason why web socket connection has been lost. Any specific callback from websocket client for specific connection lost reason.

You did not specify which programming language’ autobahn library you are talking about. That would add more context into the discussion.

···

On Thursday, October 12, 2017 at 3:11:39 PM UTC+5, Md Ali Hossain wrote:

Currently we are getting websocket connection lost either it’s Internet disconnection or WebSocket server down/unreachable. Is there any way to get specific reason why web socket connection has been lost. Any specific callback from websocket client for specific connection lost reason.

I am using autobahn-java in my android application.

···

On Thursday, October 12, 2017 at 4:11:39 PM UTC+6, Md Ali Hossain wrote:

Currently we are getting websocket connection lost either it’s Internet disconnection or WebSocket server down/unreachable. Is there any way to get specific reason why web socket connection has been lost. Any specific callback from websocket client for specific connection lost reason.

You should check the code in onClose() for that. The corresponding values are defined in IWebSocketConnectionHandler.

As for checking whether the server is down or internet is not working that’s a hard one. At least on the first disconnect we get a CLOSE_CONNECTION_LOST. On further reconnect attempts you could check the message of onClose(). For lack of internet it should say “Network is unreachable” and if server is down, it should say “Connection refused”.

Do explore the error codes and message text received in onClose() in different scenarios to be super sure.

Thanks!

···

On Thursday, October 12, 2017 at 3:11:39 PM UTC+5, Md Ali Hossain wrote:

Currently we are getting websocket connection lost either it’s Internet disconnection or WebSocket server down/unreachable. Is there any way to get specific reason why web socket connection has been lost. Any specific callback from websocket client for specific connection lost reason.