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: 27
Registered: ‎07-27-2011
My Device: curve
My Carrier: vodafone

ConnectionClosedException, getting this exception if i halt to read from server for few minutes.

hello,

 

I am getting a ConnectionCloseException again and again if i halt to read from server for few minutes. Why am i getting this exception again n again. What more i need to concern about.

 

Thanks in advance.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: ConnectionClosedException, getting this exception if I halt to read from server for few minutes.

My understanding is that the BlackBerry OS will kill a connection not used in the last 2 minutes.  If you want to keep a connection alive (I presume this is a Stream connection), then send a heart beat type message.

 

But there is typically no need to keep a connection open, when you have services like Push.  And this is not recommended practice if you wish to conserve battery life too.  So perhaps another option is to review your application design and see if you can do what you need to do without keeping a connection open. 

Highlighted
New Developer
Posts: 27
Registered: ‎07-27-2011
My Device: curve
My Carrier: vodafone

Re: ConnectionClosedException, getting this exception if I halt to read from server for few minutes.

Can you please elaborate, how to keep this connection alive, what is this heart beat type message .... and how to implement it !! no knowledge about this.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: ConnectionClosedException, getting this exception if I halt to read from server for few minutes.

[ Edited ]

I'm not the best person to discuss this, because you will find that in the real world (like Java on the PC), the TCP/IP implementation can I believe be asked to provide this keep alive itself - but this is not something I am familiar with. 

 

Unfortunately, actually deliberately, this is not implemented on the BlackBerry.  So you have to do something yourself.

 

A heartbest message is just a simple 'I'm here' message that one end sends from time to time,  The other end does not have to do anything with this, but should also reply, "I'm Here".  That way both ends know that the other is still alive (hence the term heart beat). 

 

But this message can also be used to keep connections alive, in situations where the ends (or an intervening gateway) will kill the connection if it thinks it is not active.  This is the situation here.  So the heart beat is being used to actually keep the connection alive, rather than being used as an indication of the state of health of the other end.

 

Hope this makes sense.

 

You will find more if you search the internet, here is quite a good discussion:

 

http://stackoverflow.com/questions/865987/do-i-need-to-heartbeat-to-keep-a-tcp-connection-open

 

 

Edit: I realise I have missed your question about implementing this.  You just have to agree a simple message that you or your Server will send from time to time, and the other end will respond to (but take no action on).  That is all.