Reputation: 103
we are being using web socket for the live communication between server and android app. But the main problem here is the web socket keeps disconnecting in several time intervals and we are not able to set the socket time out in both the sides. Any how many questions are asked on this topic but the results were not helpful to us.
Server : for server we are using .net and the sample is taken from https://github.com/paulbatum/WebSocket-Samples under that we took AspNetChat folder and developed socket server from that
Android Client : the sample is taken from java-websocket-1.3.0 and the code in the android is written in the way that if the socket is disconnected it will automatically reconnect.
The major issue we are facing are after some time interval say some 30min the websocket connection between the server and the client is not working. We were not able to say even if it is disconnected or not but when sending message from android the log says that it is connected to the server and the server doesn't receive the message in the onMessage function.
If there is a solution to this this would be more helpful and if there is any other alternate protocol we can check that also.
Thanks in advance
Upvotes: 2
Views: 4679
Reputation: 103
After a long research we found that the webSocket on the server side produces error on some interval (say 10min idle time) and at this idle period the onError() method is called with onClose() method. After this process the server is not closing the socket completely instead it only removes from its memory. To over come this issue we made a keep alive message which is sent and acknowledge for every minute using this even if there is any error produce both the app and the server knows and the socket is reconnected.
Result : Adding a keep alive method solved our issue.
Upvotes: 5