Reputation: 1339
I'm trying to read massive amount of data(messages) i'm getting from a server which i'm not owning. I'm using a BufferedReader object, with the function readLine() because the messages i'm getting are containing line feed(\n).
This is part of the code of the first thread:
while(!isInterrupted())
{
if((line = input_reader.readLine()) != null)
{
Util.offer_message(message_box, line);
}
}
I have been told by a support programmer(he works in the company which owns the server) that using readLine() to read messages from the socket, makes me lose data regularly.
Anyway, i can't really verify if i'm losing data or not(because i'm not owning the server).
So my questions are:
I can supply some more details if needed to understand my problem.
Thx for helping.
Upvotes: 0
Views: 55
Reputation: 310913
Is the programmer right about losing data on regularly because of the massive amount of data?
First, is the application losing data? If so, it certainly doesn't happen in this code. If he is telling you not to use BufferedReader.readLine()
on this pretext he is crazy. Or, shall we say, misinformed. Or perhaps you have misunderstood him.
If he does, then how should i handle it ? should i use a function like read(char cbuf[], int off, int len) and then spliting the messages?
No. Nothing wrong with readLine()
. That's exactly what it does, but without the bugs you will build into yours at first.
But I don't see the point of your two threads. I would lose one of them, and the queue, and just read lines directly when you want them.
NB You are ignoring end of stream. If readLine()
returns null you should exit the loop and close the socket.
Upvotes: 1