BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 12-03-2004, 02:07 PM   #1
bfrye
BBF Veteran User
 
Join Date: Aug 2004
Location: Hotwiring another Cessna
Model: OU812
Carrier: Nintendo
Posts: 3,492
Default

Please Login to Remove!

Offline  
Old 01-27-2005, 09:26 PM   #2
djlin
Knows Where the Search Button Is
 
Join Date: Dec 2004
Model: Curve
Carrier: AT&T
Posts: 44
Default Persistant TCP Connection

I'm trying to understand how a persistant TCP connection over the GPRS network could be dropped. Will it drop due to a weak signal strength? Or will it drop simply from inactivity? What are the best strategies to keep a TCP connection alive (e.g., setting the KEEPALIVE function, any other pinging strategies)? Any thoughts would be appreciated.
Offline  
Old 01-27-2005, 10:13 PM   #3
Mark Rejhon
Retired BBF Moderator
 
Mark Rejhon's Avatar
 
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870
Default

This is an excellent question. Verichat is a good case study of the challenges of trying to keep a persistent TCP/IP connection through varying reception.

You must have connection-reestablishment logic.
A persistent TCP/IP connection can drop due to:
  • IP address changes (I heard it may happen when you roam between carriers, like when you walk across the border of a country)
  • Prolonged loss of reception
  • Timeouts (TTL)
  • Carrier disconnecting an inactive socket connection
  • Radio-off/power-off
Pinging Is Usually Recommended
Use regular pinging to make sure it's alive. Null packets, for example. Idokorro uses null packets on a telnet connection. Verichat pings the Verichat server. Many carriers will terminate an inactive TCP/IP connection after 120 seconds. So the software often pings once every 30 seconds, or 45 seconds, or 60 seconds. So this is a good strategy.
Advantage: Connections are more likely to stay alive longer.
Disadvantage: Bandwidth usage caused by the ping packets. Can kill a connection more quickly during weak reception because a timeout error automatically means a disconnect, because the ping itself can trigger a timeout whenever pinging isn't necessary. (Some connections make pinging unnecessary).
However, if you've got a mechanism to reestablish connection and continue where you left off, then pinging is better than not pinging at all. And when your connection actually dies, re-establish automatically.

When you lose connection:
It's a fact of life. You will lose the TCP/IP connection eventually. You'll simply have to automatically reconnect.

How to Simulate Reception Loss:
Turn off the Radio. It's an excellent way to simulate sudden loss of reception. Make sure you test different lengths such as 5 seconds, 10 seconds, 30 seconds, 60 seconds, 2 minutes, 5 minutes, 15 minutes.

Other torture tests:
Walk around, drive around, or train/bus around in a low reception area, and let your software take the abuse. (Cycle the radio on/off can help too). You can also manually Switch Networks, for another torture test. And you can also poweroff your BlackBerry and then back on. You can poweroff your BlackBerry overnight with your software running, to make sure your software can recover gracefully from such a condition and automatically reconnect.

Recommended Ping Interval:
Interval of less than 2 minutes. Many systems have a 120 second timeout. Common intervals are 30 seconds, 45 seconds, 60 seconds, 90 seconds. (Some software uses 50 seconds, to workaround a 60 second server timeout)

How Long to Wait for a Ping Reply:
And wait for a long period for the ping reply -- even wait for at least 30 or 60 or more seconds, even 120 seconds, before you declare the connection is dead. That's because when you're in an ception area, it may be simply retrying, and your ping reply may take 120 seconds for certain packets instead of 1-2 seconds.

Data usage of pinging:
Ping logic running 24/7 in software can add approximately 100 kilobytes of data use per day per application, assuming you send about 1 ping per minute all day 24/7, and assuming the ping is counted as about 100 bytes when you include all the TCP/IP overhead.

How long can a socket survive on BlackBerry?:
Typically, expect "a few hours", and you must auto-reconnect about a few times per day. I've seen a socket survive on BlackBerry for more than 24 hours sometimes, when connected to an BES/MDS server with timeouts disabled. However, pinging can actually shorten the lifetime of a socket connection on such a link, while avoiding pinging is a problem with BES/MDS server that has timeouts enabled. Catch-22, eh?

Try to use just one persistent socket connection:
If you can have the power to do so, please do not use multiple socket connections when possible; try to multiplex everything over one socket connection. (Verichat uses four socket connections, one for each network, and gobbles more than double the bandwidth of WebMessenger, probably partially because of this) Verichat is vastly superior to WebMessenger, and there are good reasons to have 4 simultaneous connections, but if that can be avoided, then try to.


Note: BlackBerry email does not use keepalive methods -- It uses a different proprietary push method that's similiar to how an incoming SMS message "finds" you. Complex story behind the scenes with the blackberry.net "APN". For socket connections, you will have to simulate persistency using the above persistence methods, pinging, and auto-reconnects.
__________________
Thanks,
Mark Rejhon
Author of XMPP extension XEP-0301:
www.xmpp.org/extensions/xep-0301.html - specification
www.realjabber.org - open source
Offline  
Old 01-28-2005, 01:39 PM   #4
djlin
Knows Where the Search Button Is
 
Join Date: Dec 2004
Model: Curve
Carrier: AT&T
Posts: 44
Default

Thank you. A very detailed response that can actually be put into practice.
Offline  
Old 01-31-2005, 09:55 PM   #5
Mark Rejhon
Retired BBF Moderator
 
Mark Rejhon's Avatar
 
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870
Default

Here's some additional information:

Different phone networks such as CDMA, GSM/GPRS and iDEN all vary widely in reliability and pings. And BlackBerryOS versions can have an effect; such as differences in the TCP/IP stack performance.

Most pings seem to return in 2 seconds or less on all networks (much faster on iDEN networks though). I have noticed very occasional cases where ping replies can take more than 10 seconds - and sometimes 40-45 seconds. Usually in areas of low reception, especially from a moving vehicle (train, car).
__________________
Thanks,
Mark Rejhon
Author of XMPP extension XEP-0301:
www.xmpp.org/extensions/xep-0301.html - specification
www.realjabber.org - open source
Offline  
Closed Thread



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


ETERFANT Dental LED Flash Photography Oral Cell Phone Camera Filling Light Tools picture

ETERFANT Dental LED Flash Photography Oral Cell Phone Camera Filling Light Tools

$63.89



1 PCS New For Flash relay 5 Pin 24V  JQ608A /215C picture

1 PCS New For Flash relay 5 Pin 24V JQ608A /215C

$18.12



LP Weather Logic Seam And Flashing Tape (boxes) picture

LP Weather Logic Seam And Flashing Tape (boxes)

$200.00



NEW Flash Technology White Xenon Tower Flashtube Lighting:  H18030CF  picture

NEW Flash Technology White Xenon Tower Flashtube Lighting: H18030CF

$120.00



Schneider Electric XBTZGM256 256MB Compact Flash Card picture

Schneider Electric XBTZGM256 256MB Compact Flash Card

$212.23



APOC 264  FLASH N' SEAL WHITE ELASTOMERIC ROOF & FLASHING SEALANT 2 GALLONS picture

APOC 264 FLASH N' SEAL WHITE ELASTOMERIC ROOF & FLASHING SEALANT 2 GALLONS

$79.99







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