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 9086037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:23:27+00:00 2026-06-16T21:23:27+00:00

When sending requests to the localhost from Chrome the program receives two requests: one(maybe

  • 0

When sending requests to the localhost from Chrome the program receives two requests: one(maybe two) empty and one with a normal HTTP request.
When I do the same with Firefox I sometimes get a single empty HTTP request, the others are fine.
I think it has something to do with favicon, I’m not sure why there isn’t anything in the outputStream

ServerSocket server=null;
Socket socket;
try 
{   server=new ServerSocket(80);
    while(true)
    {   try 
        {   socket = server.accept();
            Worker worker=new Worker(socket);
            (new Thread(worker)).start();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

....
//Worker.java


public class Worker implements Runnable 
{   private Socket socket;
    public void run()
    {   try 
        {   InputStream inStream = new BufferedInputStream(
                                                     socket.getInputStream());
            byte[] array = new byte[1000];
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream( );
            while(inStream.available()>0)
            {   outputStream.write(array);
            }
            System.out.println("-----------------------------------------");
            System.out.println(outputStream);
            System.out.println("-----------------------------------------");

            } 
            catch (IOException e) 
            {   e.printStackTrace();
            }
            try 
            {   socket.close();
            } 
            catch (IOException e) 
            {   e.printStackTrace();
            }
        }
        public Worker(Socket socket)
        {   this.socket=socket;
        }
    }

Sample request from Chrome:

-----------------------------------------

-----------------------------------------
-----------------------------------------

-----------------------------------------
-----------------------------------------
GET / HTTP/1.1
Host: localhost
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

-----------------------------------------
  • 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-06-16T21:23:29+00:00Added an answer on June 16, 2026 at 9:23 pm

    available() isn’t a valid test for end of stream. See the Javadoc. You should read all the headers line by line until you get a blank line.

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

Sidebar

Related Questions

I'm sending an HTTP PUT request from a WinForms application and I'd like to
I am sending raw requests, and receiving raw responses through HTTP. A number of
I have a PHP script that is sending a series of http requests to
From My Previous question sending request to apple - from iphone custom application Here,
I sending ajax request from a jQuery file like below, which expects response in
I'm sending the request from Display.jsp to TrialShow.jsp page, but whenever I call ${pageContext.request.requestURL}
I have a server running at http://localhost:9080 but the http clients are sending the
I'm sending data from client sockets through a proxy server to an http server.
I have an iOS app sending requests to a PHP based web service ,
I have a C# app that is sending soap requests over an https channel.

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.