Android Question Android Sockets WriteBufferEmpty? Keep alive?

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
I have a couple of phones that connect to a tablet using Android sockets / AsyncStreams / Prefix mode.

At the end of the day, after having the tablet instruct each phone to periodically take snapshots, the phones build a zip file containing all the snapshots from the phone and send it to the tablet as binary data in 64K chunks. (The transfer has to be done at the end of the day, not when the snapshots are actually taken).

This zip file can be pretty huge (300 MB). I send the zip file in 64K chunks. I don't want to "saturate" the Wi-Fi connection with this huge transfer.

1) Is there a way on the phone to tell when each chunk has been transferred via Wi-Fi so I can pause a little, letting somebody else jump onto the Wi-Fi if they want, before I try to send the next chunk?

Something like checking for WriteBufferEmpty on the stream then pausing 5 ms before writing the next chunk.

2) Transferring one of the zip files could take a while – maybe 20 minutes. Both phones are connected to the tablet during the transfer. One phone will be sending its zip file and the other phone sitting there doing nothing waiting for a request from the tablet to begin its turn to start sending.

Will an Android Wi-Fi socket connection timeout and close if there is no activity over the connection for certain length of time?

Thanks,
Barry.
 

canalrun

Well-Known Member
Licensed User
Longtime User
Yes, that is what I'm using and everything transfers successfully – huge files and all. But, I had a heartbeat implemented and the phones were disconnecting, I think, because of the heartbeat during the large file transfers. This is all being done at a remote site. I suspect what may be happening is that the Wi-Fi is not allowing the phones to receive a response to the heartbeat in time. They disconnect.

I would like to try throttling the huge file transfer. I could just wait 500 ms between each chunk, but I'm sending 4500 chunks. At 500 ms per chunk, that's 41 minutes.

I was thinking it might be better to detect the previous chunk has been written, wait a few milliseconds, then send the next chunk. Maybe this would allow the heartbeats to sneak in.

Is there a way to check WriteBufferEmpty? or PreviousTransferComplete?

Along the same lines, I have the heartbeat (or keep alive) that I had been transferring every two seconds. I'm wondering if this is necessary?

Thanks,
Barry.
 
Upvote 0
Top