Android Question AsyncStreams - Socket.Connected when it's not - thoughts

chrisinky

Member
Licensed User
Longtime User
So I'm working with a connection to a host where I don't control the code. On my side - I send data and get a response - currently I start the connection at the start of the program and leave it open, as when users are really "going" they can transmit things at roughly 1 per second back to the server. For this reason I don't connect, send data, get response and disconnect (but maybe I should? but seems like a lot of overhead?!?!)

Currently the program works very well, except a few small cases. One specifically is some end users corporate firewalls have inactive TCP timeouts set low, so the user sits the device down while connected, it transmits no data for say 5 minutes, and the firewall ends the connection. In this case, both the server side and the android side think the socket is still connected, thus when I go to send the next packet - it transmits, but I never get any kind of reply, the 10 second timeout does not fire either. No AST errors or anything. There are also other cases, but I don't have the specifics yet, I believe that sometimes when AP hopping takes too long the same thing happens, but hard to be sure.

My biggest issue, is that the server side is hitting a database, during very busy times when say 100+ users are hitting the app/db at the same time, it may be common to not get a response for 5 seconds, so I can't add any kind of "if no response in 5 seconds, drop connection and reconnect" logic without possibly adding additional load to the server at that time.

Is there any other way I can deal with this that I'm not thinking of?

Thanks,
ChrisinKY
 

OliverA

Expert
Licensed User
Longtime User
On the client, use a timer and send an event to the server. On the server side, capture the event and do nothing. Adjust the timer interval to the largest interval which allows you to keep the firewall from shutting the connection.
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
If you don't control the code on the server side, is there some service function you can query that just returns data, e.g. a status check? If so, perhaps a timer that requests that status every 30 seconds or so, independent of what the clients are doing?

If not, the perhaps creating a transmission queue for the user's needs that is not tied to the connection and manage the connection independently?
 
Upvote 0
Top