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
m-romanuik
Posts: 114
Registered: ‎04-28-2010
My Device: Storm 9530
My Carrier: Telus
Accepted Solution

TCP Connection

Heyy,

 

     At the moment I can connect my device and simulator to my server using direct tcp with my IP and port. However when I write("Protocol Version 2\r\n"); my server receives the following number of bytes..

 

1

22

22

22

10

22

22

22

 

why does it only send 1 byte? then send 22.. Shouldn't it be consistent?

Please use plain text.
Developer
m-romanuik
Posts: 114
Registered: ‎04-28-2010
My Device: Storm 9530
My Carrier: Telus

Re: TCP Connection

For the past couple hours i've been trying to think of the reason why the bytes arent consistent. It could be because TCP connection is losing data along the way. So i could implement my server to check the number of bytes received and compare it to the expected number of bytes required to the expected input. However i do not believe its due to the lose of data.

Please use plain text.
Regular Contributor
Abhijit_RIM
Posts: 98
Registered: ‎08-31-2010
My Device: BB-9700
My Carrier: Airtel

Re: TCP Connection

TCP is a reliable stream delivery service that guarantees delivery of a data. Probably number of bytes received it totally depend upon the bandwidth you were getting on your device.

Please use plain text.
Developer
m-romanuik
Posts: 114
Registered: ‎04-28-2010
My Device: Storm 9530
My Carrier: Telus

Re: TCP Connection

Ya see I thought so. I tried do what i mentioned above however i end up getting my string cut up. Heres my code. Im not sure why TCP only sends 1 byte and then 22. Even if i change the last line to write(_protocol, 0, _protocol.length());

 

// Variables and Fields
private StreamConnection conn = null;
private String _protocol = "Protocol Version 2";
private String _url = "socket://174.117.68.8:52468;deviceside=true";

// Create Socket Connection with Input/Output Writers
conn = (StreamConnection)Connector.open(_url, Connector.READ_WRITE, false);
InputStreamReader _in = new InputStreamReader(conn.openInputStream());
OutputStreamWriter _out = new OutputStreamWriter(conn.openOutputStream());

// Write to Server
_out.flush();
_out.write(_protocol + "\r\n");
Please use plain text.
Developer
m-romanuik
Posts: 114
Registered: ‎04-28-2010
My Device: Storm 9530
My Carrier: Telus

Re: TCP Connection

I am no longer going to be ever using strings as a stream.. long live bytes...

 

http://supportforums.blackberry.com/t5/Java-Development/How-to-send-data-via-TCP/m-p/200510/highligh...

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: TCP Connection

Just a thought:

 

_out.flush();
_out.write(_protocol + "\r\n");

 

should be


_out.write(_protocol + "\r\n");

_out.flush();

Please use plain text.