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 Contributor
ssyap_dallab
Posts: 5
Registered: ‎02-08-2012
My Device: 9000
My Carrier: Singtel

Direct tcp causes data connection lost until pull out battery

I found a quite serious issue on blackberry. When blackberry only connect through direct tcp to network, after sometime data connection will drop and cannot be recovered until pull out battery. When this case happen, applications eg. BlackBerry App World will fail to connect to network. ONLY BlackBerry Browser still able to connect to network.

 

Beginning I thought this is caused by my XMPP chatting application, but after some tests and I found that it is not because of my application. It is because of after I uninstall my application, and only use Opera Browser/What's app to test, it also happen the same issue.

 

package mypackage;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.Enumeration;
import java.util.Vector;

import javax.microedition.io.Connector;
import javax.microedition.io.SecureConnection;
import javax.microedition.io.SecurityInfo;
import javax.microedition.io.SocketConnection;

public class connectClass extends Thread {

	private static SecureConnection sc = null;
	private DataInputStream is = null;
	private OutputStream os = null;
	private OutputStreamWriter writer = null;
	private InputStreamReader reader = null;
	private Object locker0 = new Object();
	

	public connectClass(){
		
	}

	public void run(){
		
		try {
			System.out.println("Start Connection ++");
			
			sc = (SecureConnection) Connector.open("ssl://talk.google.com:5223;deviceside=true");
			if(sc!=null)
			{
				SecurityInfo info;
				
					info = sc.getSecurityInfo();
					boolean isTLS = (info.getProtocolName().equals("TLS"));
					sc.setSocketOption(SocketConnection.KEEPALIVE, 1);
					sc.setSocketOption(SocketConnection.LINGER, 5);			
					
					is = sc.openDataInputStream();
					os = sc.openOutputStream();
					
					reader = new InputStreamReader(is, "UTF-8");
					writer = new OutputStreamWriter(os, "UTF-8");
					
					System.out.println("Connected");
			}
			System.out.println("Start Connection --");
		} catch (IOException e1) {
			System.out.println("open sc", e1);
		}
		
		if(is!=null)
		{
			while(true)
			{
				try {
					int i = reader.read();
				} catch (IOException e) {
					System.out.println("read", e);
					break;
				}
			}
			
		}
	
	}
	
	public void close()
	{
		try {
				if(reader != null)
				{
					reader.close();
					reader = null;				
				}
				if(writer != null)
				{
					writer.close();
					writer = null;
				}
				if(os!=null)
				{
					os.close();				
					os = null;
				}
				if(is!=null)
				{
					is.close();
					is = null;
				}
				if(sc != null)
				{
					sc.close();
					sc = null;
				}
			
		} catch (IOException e) {
			System.out.println("close", e);
		}
	}
	
}

 

In order to find out the problem, I wrote a simple test program above.

 

There are 2 buttons (connect and close), I connect to network first, then close the connection. 

After that I put my blackberry device into a shield box for 30 minutes, then take it out. Wait until device recover from no service, and then connect to network, I found that there is no problem in connection, so I close the connection and wait another 10 minutes to retry. But after 10min, I found that it may happen I cannot connect to network anymore (normally retry after 3 times it may happen). My test program throw an IOException when try to connect. I try to open BlackBerry App World, it also cannot connect to network. It ONLY can be resolved after I pull out battery to reset device.

 

After that, I uninstall my test program, only install Opera Browser or What's App, follow the same test procedure, it also happens the same issue.

 

I ever repeat the same test on 3 devices (2 devices are OS6, another is OS 7), all able to repeat.

 

My XMPP project requirement only allow direct tcp and wifi connection. 

 

Anybody also facing the same issue? May I know how to solve it?

 

Please use plain text.
New Contributor
user107
Posts: 8
Registered: ‎03-24-2012
My Device: Developer
My Carrier: 9800

Re: Direct tcp causes data connection lost until pull out battery

hey ssyap_dallab..

 

Its not with direct tcp connection as i think,,,um a newbie and also facing same prob....

with wifi and direct tcp ..both,,,,my app works fine,,,,but randomly connection lost.....

u can not get the things back untill you...pull out battery...

 

see my post..
http://supportforums.blackberry.com/t5/Java-Development/Http-IO-exception/m-p/1764977#M201913..

 

thanks,,,,, 

Please use plain text.
New Contributor
ssyap_dallab
Posts: 5
Registered: ‎02-08-2012
My Device: 9000
My Carrier: Singtel

Re: Direct tcp causes data connection lost until pull out battery

Hi user107,

 

Do you ever try to only use WIFI or only use 1 kind of connection method to test your program?

 

In order to clarify my connection problem, I will always use 1 kind of connection method, either wifi or direct tcp to test my program.

 

After testing with wifi connection, my program is running well when using WIFI connection and it is very stable when using WIFI.

 

But when I test with direct tcp connection, I found out this problem. 

 

I implemented RadioStatusListener to monitor the connection, I found that before this issue happens, blackberry will always get radioTurnedOff

 

I tried different way of testings to simulate the problem, then I found out put device into shield box 30min, and take out, wait 10min to connect, is the easiest way to repeat this issue.

 

I also tried to turn on auto reconnect method in my program, so that when I take out device from shield box, it can automatically reconnect. I found that, when I take out device from shield box, when device recover from no service, my program can reconnect back successfully. but its connection will drop within 10min. 

 

When this issue happens, I wonder why only remove battery then can recover blackberry device. I also wonder why ONLY blackberry browser still can serf net but OTHERS applications includes blackberry app world cannot connect to network.

Please use plain text.
New Contributor
bigo132
Posts: 9
Registered: ‎02-02-2012
My Device: 9700
My Carrier: china mobile

Re: Direct tcp causes data connection lost until pull out battery

Please use plain text.