Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5943685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:25:52+00:00 2026-05-22T16:25:52+00:00

I am using BufferedReader.readLine() method to read a response from a remote server (which

  • 0

I am using BufferedReader.readLine() method to read a response from a remote server (which is written in C and I have no access to source code).

BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
while((line = br.readLine())!=null){
    [...]
}

But it always blocks at the last line until it times out. So I used the following code:

int b;
while(true){
   b = in.read;
   [...]
}

and I found out that the last byte read has an integer value of 13, which I think it is a carriage return, right?

So why the readLine method blocks? How does the server usually signal an end of stream is reached? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:25:52+00:00Added an answer on May 22, 2026 at 4:25 pm

    In the case of a network connection, the stream is terminated when the socket is closed.

    So it is perfectly normal that readLine() blocks until it received an “end of line” or you close manually the connection. When your readLine() receives the last character with the ’13’ value, the line is read and the loop starts again, waiting for the next line.

    There is no difference between the “last line” and the other lines.

    In order to stop the loop, you must manually close the connection somewhere or wait for the timeout. But without more information about your communication protocol, it is impossible to be more precise about this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such code to read a text file using BufferedReader : BufferedReader reader=null;
I'm reading a file using bufferedreader, so lets say i have line = br.readLine();
Using the readLine() method of BufferedReader , can you print the first N lines
I'm trying to read input from the terminal. For this, I'm using a BufferedReader.
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
My code needs to read in all of a file. Currently I'm using the
I'm using this method to move from a state to the next on this
I have a method I am using to execute a command on the local
I have a list and i am adding a value using add(int,Object) method but
I'm using Apache Commons HttpClient to grab some data from a server. My problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.