what is the relation between HTTPServletResponse setContentLength header and keep-alive

N

Naresh Agarwal

Hi

Is there any relation between setConentLength header of
HTTPServletResponse and whether the server will "keep-alive" the
socket connection?

I want HTTPServletResponse to *close* the socket after sending the
response. For this I'm closing the OutputStream after writing the
data. But still socket is not closed and client keeps on waiting to
read from socket.

Is there way I can enfore HTTPServletResponse to close the socket?

thanks,
Naresh
 
E

ExGuardianReader

Naresh said:
Hi

Is there any relation between setConentLength header of
HTTPServletResponse and whether the server will "keep-alive" the
socket connection?

I want HTTPServletResponse to *close* the socket after sending the
response. For this I'm closing the OutputStream after writing the
data. But still socket is not closed and client keeps on waiting to
read from socket.

Is there way I can enfore HTTPServletResponse to close the socket?

thanks,
Naresh

It is the browser which opens the connection, and if it's using HTTP 1.1
(most do noawadays though you can often disable it), and if it is either
not going through a proxy, or the proxy server maintains the 1.1
keepalive connection, then it will maintain the TCP/IP connection in
order to make subsequent HTTP requests a bit faster.

In 1.0 there was a keepalive header which could be specified by the
browser in its request: http://www.io.com/~maus/HttpKeepAlive.html

If you don't want this use

response.setHeader("Connection", "close");

in your servlet: http://www.jmarshall.com/easy/http/#http1.1s4

Nige
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,286
Latest member
ChristieSo

Latest Threads

Top