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: 445
Registered: ‎10-14-2008
My Device: Blackberry Bold 9000

StreamConnection

i m working on GPSDemo sample.

its receiving data from socket server but not able to send message to server.

 

Code :

 

 

try { connection = (StreamConnection)Connector.open(_url, Connector.READ_WRITE, false); _in = new InputStreamReader(connection.openInputStream()); _out = new OutputStreamWriter(connection.openOutputStream()); //write the data to the server String data = "$RGTK,1234,12082005125349,A,23.8547,E,61.4496,N,11,0,0,9,0,0,0,0,0,20081230071138&"; _out.write(data, 0, data.length()); _out.write(52); //_out.write("$RGTK,1234,12082005125349,A,23.8547,E,61.4496,N,11,0,0,9,0,0,0,0,0,20081230071138&"); //_out.write('z'); //write a terminator //wait for an ack, in this case an 'R' character, for 'Received' int c = _in.read(); while(c > -1) { System.out.println("Char :: " + (char)c); c = _in.read(); } //debug // System.out.println("GPSDemo: Debug: exchange(): received ack char:" + c); _delay = DEFAULT; //reset the backoff delay error = false; //clear any error } catch (IOException e) { error = true; _delay = increaseDelay(_delay); GPSDemo.this.updateLocationScreen(e.toString()); //push this data back on the stack, it's still pending synchronized (this) { _data.insertElementAt(data, 0); } } finally { try { if(_in!=null) _in.close(); if(_out!=null) _out.close(); if(connection!=null) connection.close(); } catch (IOException ioe) { //no-op - we don't care on close } } }

 

 

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thanks & Regards
Zahid Naqvi | Senior Software Engineer
BlackBerry Development Advisor
Posts: 15,017
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: StreamConnection

What problem are you having?  Is an exception thrown?  Does it fail to connect or does it connect and fail to send the data?  What route is the connection being made over?

 

What Is - Different ways to make an HTTP or socket connection
Article Number: DB-00396

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 445
Registered: ‎10-14-2008
My Device: Blackberry Bold 9000

Re: StreamConnection

Click Here

n see in detail

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thanks & Regards
Zahid Naqvi | Senior Software Engineer