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

  • Home
  • SEARCH
  • 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 6938633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:31:03+00:00 2026-05-27T12:31:03+00:00

I am supposed to develop a program that reads a web page with the

  • 0

I am supposed to develop a program that reads a web page with the specified URL, but the problem is that I am not allowed to use any HTTP libraries, I am only allowed to use TCP.

Below is the code that reads the response message:

private static String readMultiline (BufferedReader inStr) {
    String message="";
    String line=readLine(inStr);

    while (line != null) {
         message += line + "\r\n";
         line=readLine(inStr);
    }

    if (message.length() == 0) return null;
        return message;
}

private static String readLine (BufferedReader inStr) {
    String line = null;
    try{
         line = inStr.readLine();
    } catch (IOException ioe) {
         System.out.println("ERROR: Incoming packet could not be read properly.");
         return null;
    }
    return line;
}

The problem is that the header and the web page content are completely received, but the while loop still waits for the ‘next’ line, which does not exist. After a while, timeout occurs and the code continues. The server I am trying to connect to does not do “Connection:close”. How can I detect the end of the file?

  • 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-27T12:31:04+00:00Added an answer on May 27, 2026 at 12:31 pm

    Other answers were deleted so I will post one up. You are using an IO method that read lines of information, with a line being defined as a set of characters terminated by a newline character. But there is no guarantee that your TCP packets are ending in newline, so you need to use a more agnostic IO read to process them.

    Take a look at DataInputStream, it has a convenience method called readFully that I think you will find quite helpful.

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

Sidebar

Related Questions

I ask this because at work I am supposed to develop a web-application that
Are we supposed to find workarounds in our web applications so that they will
i want to develop a pretty basic client-server program. one software reads xml (or
I want to develop a Java EE6 application that contains some Web-GUI functionality. Suppose
Suppose I develop an application with the logic as a CLI program that can
Although my question might seem abstract I hope it's not. Suppose I develop an
I'm supposed to create a simple rule engine in C#. Any leads on how
I don't have a lot of experience developing web-based data entry software, but comparative
I am trying to develop a sample application that finds the process name of
I'm using VS2010,C# to develop my ASP.NET web app, sometimes I need to declare

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.