I am using javascript websocket client in android(Cordova) application. I have observed that if i disconnect WIFI connection of mobile, there is no ws.onClose event called and because of this i unable to connect back to websocket server when WIFI get connected on phone. I try to add a interval in javscript which check after few seconds that what is the state of websocket but ws.readyState always give a same state either WIFI connected or not. Is there any i can check that either ws is connected or not in java script?
Asked
Active
Viewed 1,400 times
0
-
https://github.com/websockets/ws#how-to-detect-and-close-broken-connections – Shilly Jul 06 '18 at 15:15
-
i have seen this already, but it is for server side implementation as far i can understand – user565 Jul 06 '18 at 15:17
-
I haven't worked with websockets yet, but you could check your internet connection and react on the different types. edit: [how-to-wait-for-a-websockets-readystate-to-change](https://stackoverflow.com/questions/13546424/how-to-wait-for-a-websockets-readystate-to-change) <- or this could help – schogges Jul 06 '18 at 15:26
-
Or use socket.io instead of webSocket which does automatic connection detection and reconnect for you. socket.io uses webSocket as the base level transport, but adds a number of features on top of it. – jfriend00 Jul 07 '18 at 02:52
-
Actually changing to socket.io is not a small change as far i can see by following post https://oneminutedistraction.wordpress.com/2013/08/12/marrying-socket-io-client-with-java-ee-7s-websocket/. This is an old post so is there any any alternative now so that i can connect to Websocket Server from socket.io directly without creating a new servlet etc ? – user565 Jul 09 '18 at 10:10