View Single Post
Old 11-20-2011, 02:40 PM   #2 (permalink)
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default Re: How to Read from a socket ??

This is the code snipit from the OS 6 API:

Code:
   SocketConnection sc = (SocketConnection)
                         Connector.open("socket://host.com:79");
   sc.setSocketOption(SocketConnection.LINGER, 5);

   InputStream is  = sc.openInputStream();
   OutputStream os = sc.openOutputStream();

   os.write("\r\n".getBytes());
   int ch = 0;
   while(ch != -1) {
       ch = is.read();
   }

   is.close();
   os.close();
   sc.close();
Any code that may block (such as socket reads or writes) must be run on a thread separate from the event thread.
__________________
My other Blackberry is a PlayBook.
Offline   Reply With Quote