I'm using org.java_websocket.WebSocket
to create a Websocket server on my Android device. I have clients on desktop connected to it.
I want, when WiFi is unavailable, to shut down the server and notify clients of the disconnect. What happens is when I have a broadcast receiver as below, it shuts down the server but the clients don't realize it for a very long time. Is there any reason for this?
public void onReceive(Context context, Intent intent) {
ConnectivityManager conMngr = (ConnectivityManager)context.getSystemService(context.CONNECTIVITY_SERVICE);
NetworkInfo wifi = conMngr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo mobile = conMngr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
// Perform operations here to shut down web socket server
}
Basically when Wifi is not available, I want to be able to shut down the server and the clients to be notified. Why is it that when I do conn.close()
for each connection I don't get the notification on the desktop client?
Also, one of my clients is a Mac Client that uses Starscream
(https://github.com/daltoniam/Starscream). Not sure if there is anything about that I should be aware of.
If your WebSocket server is fully compliant with the IETF specification, it should understand WS ping/pong control frames. If it doesn't (and your client code doesn't), then you need to investigate your TCP timeout settings. TCP timeouts can be many minutes. Recall TCP was designed to retry when the connection fails.