Hel Hel - 7 months ago 47
Java Question

How to output HTTP request message correctly

I use the following code to output HTTP request message. But the loop never ends after outputing HTTP request from browser. It seems that

just waiting for new bytes after outputing HTTP request.

InputStream inputStream = socket.getInputStream(); // socket is returned by
// serverSocket.accept()
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));

// output HTTP request
String line;
while ((line = bufferedReader.readLine()) != null) { // the loop never ends


This is happening because the peer connection is never getting closed. If it never closes, readLine() won't return null.