Thank you for visiting the BlackBerry Support Community Forums.
- Kevin Michaluk, Founder, CrackBerry.com
12-08-2008 05:10 PM
I have an application that performs 2-way data transfer over a TCP socket (devicesie=true). I want to make sure that I don't lose any data that I sent, i.e. if the network connection closes abruptly, I want to detect it and buffer my data to be sent later.
My test is turning off the radio on the blackberry device (8820, OS 4.2).
When I have a constant stream of outbound data (about 100 bytes every sec), I don't get any exceptions thrown immediately after the disconnect, so there is no way for me to detect the problem and recover the data. This data also never gets to the server (confirmed with wireshark).
Eventually (within a second - on a second write attempt), an exception gets thrown and I can reconnect and resend.
I've tried setting the outbound (and inbound) socket buffers to 50 bytes, but I still lose data (although anecdotally less frequently).
I also call .flush() immediately after each .write(char b).
Has anyone encountered this problem?
How do I make sure that no data gets lost in these cases?
12-08-2008 06:18 PM
You can packetize the data and serialize the packets. If a packet fails you can resend the last packet and the current packet.
On the receiving side, the "catcher" needs to ignore a duplicate packet (same serial number).
There are more complex ways to do this, but this one is simple to implement and fairly foolproof.
12-12-2008 04:38 PM
Thanks for the suggestion, but I am using a standard protocol with a 3rd party server (XMPP). My data is already being sent in packets (text messages). Resending the previous message does not work either, because several messages can get lost, and I don't know how may actually didn't make it through (it's not just the last one).
Of course, some type of an application layer ACK would do the job, but I can't do that in this case.