BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 05-11-2007, 03:48 AM   #1 (permalink)
New Member
 
Join Date: May 2007
Model: 7100T
PIN: N/A
Carrier: test
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Connection latency

Please Login to Remove!

i have develop client application in blackberry which is connect and then waiting data from server. When trying in emulator the latency is none, but when deployed to device using GPRS, the latency is huge, and because the app suppose to be real time, it become an issue. Do you have solution for that.

here are the snapshot of connection code:

public void run() {
try {
iSockInputStrm = iEngine.iSocket.openInputStream();
while (! stop) {
try {
int ch;
char cc;
boolean isTail = false;
StringBuffer buf = new StringBuffer();
while((ch = iSockInputStrm.read()) != -1) {
cc = (char) ch;
buf.append(cc);
if (isTail) {
if (cc != TypeDef.DATA_TAG) {
// process packet
buf.delete(0, buf.length());
}
isTail = false;
}

if (cc == TypeDef.TAIL_CHAR) {
isTail = true;
}

try {
Thread.sleep(1);
}
catch(Exception e) {
}
}

try {
Thread.sleep(1);
}
catch(Exception e) {

}
}
catch (Exception e) {
break;
}
}
}
catch (Exception e1) {
}
}
Offline  
Old 05-13-2007, 09:53 AM   #2 (permalink)
Talking BlackBerry Encyclopedia
 
Skipper_Joe's Avatar
 
Join Date: Jan 2007
Location: Kharkov, Ukraine
Model: 8300
Carrier: N/A
Posts: 237
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Couple of common strategies:
1) Send your updates to server asynchronously so it will not affect responsiveness of UI.
2) Cache data, downloaded from server, on your device. It allows you not to repeat requests to server and increase response time to user in some cases.
Offline  
Old 05-15-2007, 01:37 PM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Feb 2007
Model: 9000
Carrier: SFR
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,


I had some troubles too to read using socket on BB.
What I recommend is the following:

firstChar = (char)inputStream.read(); //Blocking command
nbr_byte = inputStream.available();
byte_result = new char[nbr_byte + 1];
byte_result[0] = firstChar;
for (int cpt = 0; cpt < byte_result; cpt++) {
byte_result[cpt+1] = inputStream.read();
}

//Don't forget to use thread.

Hum perhaps it can be customized, but
1/read[1]
2/available
3/read[n]
seems to be the good solution.
Offline  
Old 05-27-2007, 03:48 PM   #4 (permalink)
Retired BBF Moderator
 
Mark Rejhon's Avatar
 
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870
Post Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by abahadilah View Post
i have develop client application in blackberry which is connect and then waiting data from server. When trying in emulator the latency is none, but when deployed to device using GPRS, the latency is huge, and because the app suppose to be real time, it become an issue. Do you have solution for that.
Burst the data out in 500 millisecond bursts at the minimum -- GPRS can only transmit about one to three packets per second, so if you have a realtime application (i.e. telnet), you should buffer all your packet transmissions and burst them out on a 500 millisecond timer (approximately). Either for incoming and outgoing data where possible. That way, it doesn't end up lagging for more than 1 second (which can happen if you rapid-fire transmit many packets. You can transmit up to about 5 kilobytes per second over GPRS, but to do so, you need to burst them out efficiently. GPRS is very bottlenecked in terms of number of packets per second. In fact, you can get less latency bursting a single 1Kbyte packet, than transmitting three separate 100-byte packets!

Server side programming: Make sure the server bursts out the data all at once, so the BlackBerry can read it all at once, quickly
Client side programming: Make sure the client bursts out all data necessary, in as short time period..

Regardless of the technique, you still have appoximately 600 to 1000 milliseconds of unavoidable latency -- but at least it won't be much worse than that (which can happen if you transmit multiple packets in rapid-fire fashion)
__________________
Thanks,
Mark Rejhon
Author of XMPP extension XEP-0301:
www.xmpp.org/extensions/xep-0301.html - specification
www.realjabber.org - open source

Last edited by Mark Rejhon : 05-27-2007 at 03:53 PM.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.