I'm responsible for some code on an Android device which talks to a PC over WiFi via a wireless access point (WAP), using TCP sending packets back and forth. On the PC side the software uses winsock to send and receive packets with the Android device, but I have no access to, or control over, the PC side of this connection.
This architecture works fine sending and receiving, but if there is no traffic for exactly 1 minute, then if the PC attempts to send a packet to the Android it gets an RST back, as though the Android is no longer listening. Winsock, on the PC side, is interpreting this is a timeout.
The Android device is configured to keep the WiFi "always on". I'm using a java.net (Android API 16) socket in my code. Is there something I can check on that socket periodically, or an event I can receive to see if I've stopped listening?
(Edit) I'm specifically referring to whether the Android is listening. After 1 minute the Android device can still send. Here's a Wireshark trace that illustrates this:
- 11 10.1.2.1 10.1.2.11 TCP 79 42825→181 [PSH, ACK] Seq=1 Ack=1 Win=8170 Len=13 7
- 12 10.1.2.11 10.1.2.1 TCP 89 181→40574 [PSH, ACK] Seq=1 Ack=14 Win=259 Len=23
- 13 10.1.2.1 10.1.2.11 TCP 60 40574→181 [RST] Seq=14 Win=0 Len=0
The Android is 10.1.2.1, the PC is 10.1.2.11. In this example I initiated a send from the Android TO the PC, and it went just fine. The PC tried to send something in response, but the Android sent an [RST]
Also N.B. that this only refers to TCP - if the PC tries to ping the Android after 1 minute it still gets a response, but ping is ICMP.
Edit 2
Someone wanted to see how I create the socket. So here it is:
new SocketPermission(new String(new StringBuilder(configLGIP).append(":180-")), "connect,accept,listen");
// Open a socket to the front end
Log.d("StartTCP", "attempt IP " + configLGIP);
try {
sock = new Socket(configLGIP, 180 + SafeActivity.pdanum);
}
Later I do...
if (sock != null) try {
sock.setTcpNoDelay(true);
bin = new BufferedInputStream(sock.getInputStream());