Search code examples
javasocketsserversocket

Java Socket multiple requests


I have built a small webserver which accepts requests. Problem is that if I open it inside my browser my application shows that 4 requests have been received. Why 4 and not just 1?

while (true) {
        try {
            Socket remote = s.accept();

            String sendersIP = remote.getInetAddress().toString();
            log.add(sendersIP);

                System.out.println("Got new Request");

                out.println("HTTP/1.0 200 OK");
                out.println("Content-Type: text/html");
                out.println("Server: Bot");
                out.println("");
                out.println("<H1>Welcome</H1>");

            out.flush();
            remote.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Solution

  • Looks like this was my browsers (Chrome) mistake... If I send a request from eclipse it only appears once.