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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
sam_mor
Posts: 54
Registered: ‎05-28-2009

Sockect Disconnections

Hi Guys,

I am developing an application for blackberry bold 9000 .

this application use TCP/IP Direct connections to connect, send data to a server application.

connnecting using a  thread:

 

connection = (StreamConnection)Connector.open(URL);
os = connection.openDataOutputStream();

 

Sending Data every 3 minutes:

try
            { 
                        os.write(tosend.getBytes());
            }
             catch(ConnectionClosedException dis)
            {
                new ConnectThread().start();
            }

 

 what is happening on the server is this:

connection established

send data for several times

connection abondaned

connection established

send data for several times

connection abondaned

 

this process hapens again and again..

 

what is strange,:

1. sometimes i have connectionclosedexception, sometimes not when reconnecting

2. the ip address remains the same even i use this application all the day long

 

 

Any explanations?

 

thanks

Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009

Re: Sockect Disconnections

[ Edited ]

NAT. I'm not 100% sure that's the reason, but I believe carriers' NAT rules have short expiration times. So, if you aren't sending and receiving often enough (typically every 80-120 seconds, but on some carrier+APN combinations the intervals may be much longer) via an established (NATed) TCP connection, the NAT rule gets removed and the connection no longer works.

 

P.S. Make sure you explicitly invoke OutputStream.flush() to let the TCP stack know you want the buffered data sent immediately.

Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009

Re: Sockect Disconnections

Another interesting theory is that it is the BlackBerry's network stack is responsible for timing out connections that have no traffic. At least one carrier claimed that it's not their firewall/NAT that's closing the connection, but rather that they receive an RST packets from BlackBerrys.

Please use plain text.
Developer
sam_mor
Posts: 54
Registered: ‎05-28-2009

Re: Sockect Disconnections

I am not sure what to say, I was investigating, i didnt reply back.

 

my device is always sending data every 3 minutes, so there is no idle time for sockets.

 

but still disconnection detected on the server side then a exception catched on the device 

the IP address when connecting and disconnecting is the same for the whole day => i think that mean it's not a problem of Telco

 

please advice

 

Please use plain text.
Developer
peter_strange
Posts: 17,655
Registered: ‎07-14-2008

Re: Sockect Disconnections

Can you change the 3 minutes to something less than 2 minutes and try. 

Please use plain text.
Developer
sam_mor
Posts: 54
Registered: ‎05-28-2009

Re: Sockect Disconnections

as you see, it's the same

 

Connection Established
[58.111.55.174] ..:. úøŇ3<
[58.111.55.174] ..:. úøŇ3<
[58.111.55.174] ..:. úøŇ3<
[58.111.55.174] ..:. úøŇ3<
[58.111.55.174] ..:. úøŇ3<
[58.111.55.174] ..:. úøŇ3<
[58.111.55.174] ..:. úøŇ3<
[58.111.55.174] ..:. úøŇ3<
Connection Abandonned
Connection Established
[58.111.55.174] ..:. úøŇ3<

Please use plain text.
Developer
peter_strange
Posts: 17,655
Registered: ‎07-14-2008

Re: Socket Disconnections

Odd, might try recreate.

 

We had some socket issues with old firmware on Bold, what OS level are you running?

Please use plain text.
Developer
sam_mor
Posts: 54
Registered: ‎05-28-2009

Re: Socket Disconnections

v 4.6.0.247 ( patform 4.0.0.206)

crypt kernel v 3.8.5.5.50a

branding version 1.0.146.168

 

Please use plain text.
Developer
Aviator168
Posts: 705
Registered: ‎09-10-2009
My Carrier: Verizon

Re: Socket Disconnections

I had problem sending TCP data before the software in my Bold was updated, but didn't try to reproduce it after the update. It was different problem. The send command will stall after certain amount of data was transmited, but the server never saw the connection dropped. I know NAT is in play here, especially for UDP.  The gateway tend to drop the association after about 3 minutes and you will get a new address starting the next transmision. However, if you constantly transmiting and receiving data, the gateway will keep it open indefinitely.

Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009

Re: Sockect Disconnections

[ Edited ]

The fact that that source IP address (as seen from your server) doesn't change doesn't say much. You need to look at the combination of source IP address and TCP source port.

 

P.S. If you use WAP 2.0 TCP, then the gateway sometimes adds lots of "interesting" effects, such as disconnecting one side without disconnecting the other. I suggest you set your Event Log to Debug level, and then check whether the OS is issuing normal Direct TCP connections or WAP 2.0 TCP ones. You can tell if WAP 2.0 TCP is used by the following two signs: (1) WAP APN is used for the underlying tunnel instead of the "internet" APN, (2) the underlying "tcpsocket" protocol connection is opened to a WAP gateway IP instead of the host name that you pass into Connector.open().

Please use plain text.