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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:43:16+00:00 2026-05-29T07:43:16+00:00

I wrote a simple java Server programming which just accept a connection and print

  • 0

I wrote a simple java Server programming which just accept a connection and print “Sending response” into screen. When I use safari to connect this server, the server print the result one time, which is a correct result. However, when I reload the page, there will be three “Sending response” to print into the screen. Could anyone can help me?

public class Server {
    public void runServer() throws Exception{
     ServerSocket socketServer = new ServerSocket(3721);
    System.out.println("Listerning for connections on port:"+socketServer.getLocalPort());
    while(true){
        Socket socket = socketServer.accept();
        System.err.println("Established with:"+socket);
        String request = parseRequest(socket);
        String response = createResponse(request);
        sendResponse(response);
        socket.close();
    }
    }

public String parseRequest(Socket socket){
    return "request";
}

public String createResponse(String request){
    return "response";
}

public void sendResponse(String response){
    System.out.println("Sending response");
}

public static void main(String[] args) throws Exception{
    Server server = new Server();
    server.runServer();
}
}

The outputs are:

Listerning for connections on port:3721
Sending response
Established with:Socket[addr=/0:0:0:0:0:0:0:1%0,port=59055,localport=3721]
Sending response
Established with:Socket[addr=/0:0:0:0:0:0:0:1%0,port=59065,localport=3721]
Established with:Socket[addr=/0:0:0:0:0:0:0:1%0,port=59066,localport=3721]
Sending response
Sending response
Established with:Socket[addr=/0:0:0:0:0:0:0:1%0,port=59067,localport=3721]
  • 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-29T07:43:17+00:00Added an answer on May 29, 2026 at 7:43 am

    When you create the request in Safari to the page, Safari is probably trying to fetch other items in the background, which your servlet is picking up.

    One obvious one is the favicon which is displayed next to the URL and for icons in bookmarks.

    You should print out what the URI path is in the request to figure out exactly what the requests are. You could use the path to filter out ‘valid’ requests from ‘invalid’ requests.

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

Sidebar

Related Questions

I wrote this simple Java program which connects to internic server and returns the
I wrote a simple web service in C# using SharpDevelop (which I just got
I wrote a simple client/server in java that transfers files using java NIO Socketchannel.
just had a question to a simple chat program i wrote in java. The
I am new to java NIO. I have to write a simple server client
I wrote simple load testing tool for testing performance of Java modules. One problem
I wrote a simple javascript image rotator which picks a random image on each
I wrote a simple CMS for one of my clients which does specifically what
I wrote a simple .BAT script, I scheduled it in windows server for backup
I've got a very simple java program (J.java, see below) on my application server

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.