Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 2
Registered: ‎12-08-2008
My Device: Not Specified

Lost data on network connection drop

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?

 

Thanks.

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Lost data on network connection drop

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.

 

 

 

 

Highlighted
New Developer
Posts: 2
Registered: ‎12-08-2008
My Device: Not Specified

Re: Lost data on network connection drop

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.