Stack Exchange
Using BufferedReader.readLine() with sockets and stuck in an infinite loop
I'm working on a basic TCP server and I've come to the point that I need to handle all incoming lines from the client (the browser) and I've made this loop to detect wether it is GET or HEAD or if-modified-since or whatever I'd want to add to detect.
while ((acumulador = sEntrada.readLine()) != null) {
            if (acumulador.startsWith("GET") || acumulador.startsWith("HEAD")) {
                recibido = acumulador;
                System.out.println("SERVIDOR: Recibido " + acumulador);
                //Troceamos la entrada en tres
                StringTokenizer tokens = new StringTokenizer(acumulador);
                while (tokens.hasMoreTokens()) {
                    aux.add(tokens.nextToken());
                }
                tipo = aux.get(0);
                archivo = aux.get(1);
                version = aux.get(2);
            } else if (acumulador.toLowerCase().startsWith("if-modified-since")) {
                StringTokenizer tokens = new StringTokenizer(acumulador);
                while (tokens.hasMoreTokens()) {
                    aux2.add(tokens.nextToken());
                }

            } else {
                System.out.println("SERVIDOR: Recibido " + acumulador);
            }

        }

The problem is that this is the output:
SERVIDOR: Conexion establecida con /127.0.0.1 al puerto 5000
SERVIDOR: Recibido GET / HTTP/1.1
SERVIDOR: Recibido Host: 127.0.0.1:5000
SERVIDOR: Recibido Connection: keep-alive
SERVIDOR: Recibido Cache-Control: max-age=0
SERVIDOR: Recibido Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
SERVIDOR: Recibido User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22
SERVIDOR: Recibido Accept-Encoding: gzip,deflate,sdch
SERVIDOR: Recibido Accept-Language: es,en-US;q=0.8,en;q=0.6
SERVIDOR: Recibido Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
SERVIDOR: Recibido Cookie: __utma=1.1831406279.1361823043.1361997547.1362010032.7; __utmc=1; __utmz=1.1361823043.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
SERVIDOR: Recibido 

It looks good, right? It reads everything like I want it to read but the problem is that it does not stop reading, the client never receives anything back from my server because the server never gets out of that loop, like .ReadLine() never got back 'null' and stopped.
What am I doing wrong?

If the server never got null, the client never closed the connection.

But I don't want him to close the connection, because I need to reply to his petition. How can I just read all the petition lines and then go to the part where I handle the reply.
