Ian
Ian

Reputation: 501

Android TCP read several line

Does Android TCP Socket Client read one more line the response??

inputStreamReader = new InputStreamReader(socket.getInputStream());
bufferedReader = new BufferedReader(inputStreamReader); 
response = bufferedReader.readLine();
response = bufferedReader.readLine();
Log.i(TAG, "Response :: " + response);

I cannot read two line. Because my server will response 200 OK \n Content.......

And the content will stream to the client every seconds, I don't wanna connect the socket every times. Can sbd help??

Upvotes: 2

Views: 2980

Answers (1)

jgauffin
jgauffin

Reputation: 101140

An example that will continue to read until an empty new line is found:

inputStreamReader = new InputStreamReader(socket.getInputStream());
bufferedReader = new BufferedReader(inputStreamReader); 
String line = bufferedReader.readLine(); // add first line
while (line != "")
{
    response += line;
    line = bufferedReader.readLine();
}
Log.i(TAG, "Response :: " + response);

Upvotes: 1

Related Questions