BlackBerry Forums Support Community

Closed Thread
LinkBack Thread Tools
Old 10-06-2005, 03:02 PM   #1 (permalink)
New Member
Join Date: Sep 2005
Model: 7250
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default readline from a socket connection

Please Login to Remove!

I have an app I'm working on which needs to read lines of text from a socket connection, delimited by carriage returns. What's the most efficient way to do that? I'm using DataInputStream. I see how to read individual bytes, which I wanted to avoid, and I see how to read x characters at a time, which seems to be missing carriage returns altogether. Is reading byte-by-byte my only option here? Isn't that rather slow?
Old 10-06-2005, 03:40 PM   #2 (permalink)
Thumbs Must Hurt
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 9800
Carrier: AT&T
Posts: 82
Post Thanks: 0
Thanked 0 Times in 0 Posts

If you want a readLine function, then you would need to read byte by byte so you could stop at a EOL and the function then returns all characters up to the EOL. Typically, a readLine() does not include the EOL characters themselves.

If you want to read a chunk of data, then you would have to read all the server data and split up the big chunk into its individual lines. If you stopped once you found an EOL in your chunk, then your reader routine would have to save the remaining chars (after the EOL) so it could append its next read. This would not be a good approach.

As for byte by byte reading being slow. I believe the byte read would be occuring on a buffer of data that was sent down from the server, and not doing a byte read request back to the server.


Copyright 2004-2016
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.