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
Developer
Posts: 139
Registered: ‎10-24-2010
My Device: BlackBerry 10 Dev Alpha
My Carrier: du
Accepted Solution

Tunnel Failure.... :(

hi guys.. 

 

I am facing problem in connection..  I run both server and client on same system its working fine.

 

but when I run server on network system and client on anyother machince there is message came on client side during the connection..

 

"Tunnel Failure.. "

 

even i check network and try to ping boths systems to each other no problem in ping. 

 

See this is my server Code which is in J2se

 

providerSocket = new ServerSocket(2000);
			
System.out.println("Waiting for connection");

connection = providerSocket.accept();

System.out.println("Connection received");

//3. get Input and Output streams

out=new DataOutputStream(new BufferedOutputStream(connection.getOutputStream()));

in=new DataInputStream(new BufferedInputStream(connection.getInputStream()));
do{
   try{
	byte b[]=new byte[1024];
	in.read(b);
	message = new String(b);
	if(message.equals("501"))
	sendMessage("hello some message");
	else
	sendMessage("601");
	System.out.println("client>" + message);
	}
	catch(Exception ex){
	System.err.println("Exception in do while : "+ex.getMessage() );
	}
  }while(!message.equals("bye"));

 

 

This one is client side code running on blackberry..

 

 

SocketConnection requestSocket = null;

ConnectorUi connectorUi = null;
DataInputStream in = null;
DataOutputStream out = null;
String response = null;
String message;
MainScreen screen = null;
int mno = 501;
requestSocket = (SocketConnection) Connector.open("socket://176.249.0.17:2000", Connector.READ_WRITE); out = requestSocket.openDataOutputStream(); in = requestSocket.openDataInputStream(); sendMessage(mno++ + ""); String resp = readResponseFromStream(); if (resp.equals(String.valueOf(601))) { screen.add(new LabelField("Error in packet")); } else {........printing... } BlueFreeConnection.getUiApplication().pushScreen(screen); } catch (Exception e) { e.printStackTrace(); } } private String readResponseFromStream() throws Exception { byte[] b = new byte[1024]; in.read(b); message = new String(b); return message; } private void sendMessage(String msg) { try { out.write(msg.getBytes()); out.flush(); screen.add(new LabelField("client>" + msg)); } catch (IOException ioException) { ioException.printStackTrace(); } }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

--
please mark posts as solved if you found a solution.
press the like button on the right side to thank the user that helped you.
------------------------------------------------------------
Riz
Highlighted
Contributor
Posts: 44
Registered: ‎10-28-2010
My Device: Not Specified

Re: Tunnel Failure.... :(

try

 

requestSocket = (SocketConnection) Connector.open("socket://176.249.0.17:2000;deviceside=true", Connector.READ_WRITE);

 

Developer
Posts: 55
Registered: ‎07-30-2009
My Device: Not Specified

Re: Tunnel Failure.... :(

you need to append apporipriate connection URL Parameter (depending on the connection type you are using(BES/BIS/WAP/TCP),  see the following thread, it may help you.

 

http://supportforums.blackberry.com/t5/Java-Development/ksoap2-WebService-connection-timed-out/m-p/6...

Developer
Posts: 139
Registered: ‎10-24-2010
My Device: BlackBerry 10 Dev Alpha
My Carrier: du

Re: Tunnel Failure.... :(

thanks lironhel your solution is working..

--
please mark posts as solved if you found a solution.
press the like button on the right side to thank the user that helped you.
------------------------------------------------------------
Riz