0

I am facing a strange issue with Android's airplane mode and a Socket exception 30 seconds after opening a new Socket connection.

Here's what I do on my app that creates an issue:

  1. Have an opened Socket connection and turn on and off airplane mode.
  2. Reopen a new Socket connection with the server.
  3. Wait 30 seconds and get a java.net.SocketException: Software caused connection abort on a DataInputStream readByte() call.

I have checked my server logs and the server is not disconnecting the client.

Does anyone know what could cause this? I've browsed other posts with the same exception, but they all had a more detailed error message. I can also send and receive messages with that Socket connection fine for 30 seconds, but then it randomly throws an exception.

ThomasFromUganda
  • 300
  • 2
  • 10
  • The data connection pipe is effectively broken when you toggle airplane mode so you will have to re-establish the connection again – Rafsanjani Feb 08 '20 at 05:48
  • @Rafsanjani Yes, I catch the initial exception when airplane mode is turned on. I close the socket connection and close the data streams. Then, when airplane mode is off, I make a new socket, connect it to the server, and then make the new data streams from the socket. Everything seems to work fine. After I get the exception 30 seconds after reconnecting after turning off airplane mode, I try to reconnect and then the connection works fine. I really don't get it. – ThomasFromUganda Feb 08 '20 at 05:57

1 Answers1

-1

i think to mange this case , opening airplane mode and turning of you should make listener for internet connection and when internet state change to there is connection rebuild your socket and when state changed to no internet close the socket you CAN find an example on Internet connectivity change listener here