Meaningless Drivel is fun!*
The moose likes Sockets and Internet Protocols and the fly likes Problem in URL Concept(need help urgently) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Problem in URL Concept(need help urgently)" Watch "Problem in URL Concept(need help urgently)" New topic
Author

Problem in URL Concept(need help urgently)

Deepa Raghuraman
Greenhorn

Joined: Nov 26, 2001
Posts: 13
hi,
I want to know, how to keep the connection alive after sending the first request. i used the following stmt
setRequestProperty("Connection","Keep-Alive"). but still the connection is closed after first request . Iam using HTTP/1.0.
Can anyone tell me a way to keep connection alive until I specify it to close?

Using URL, we establish connection with a server to particular file. Is there any method in HttpURLConnection or URLConnection where u can specify the file to access rather than specifying the file name at the time of connection.So that I can make multiple request to access different file each time.
I need it urgently .
Thanks in advance,
Deepa Raghuraman
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
First off, keepalive is only supported by HTTP 1.1. If you are really using 1.0 then it will never work.
Second, I understand (but have not verified) that keepalive is transparently supported by the URL class since JDK 1.3. See the networking enhancements (bottom).
Finally, to retrieve a different file you need to instantiate a different URL. This should not interfere with the keepalive feature, but again, I've never verified this.
Keepalive is controlled by the http.keepAlive system property. This was first properly documented in version 1.4 of the SDK.
- Peter
Deepa Raghuraman
Greenhorn

Joined: Nov 26, 2001
Posts: 13
hi,
Thanks for replying. In java.sun.com site, i read that HTTP1.0 by default has Connection : close which can be made presistance connection using Keep-Alive and HTTP1.1 by default has Connection : keep-alive.
According to ur reply,HTTP1.0 closes the connection after each request and keep-alive cannot be used in it.
Can u tell be how to upgrade HTTP1.0 to HTTP1.1?I need to keep connection presistant until client says explicitly to close.
It would be very helpful if reply it soon.
Thanks,
Deepa Raghuraman
gautam shah
Ranch Hand

Joined: Oct 29, 2000
Posts: 72
Originally posted by Deepa Raghuraman:

I need to keep connection presistant until client says explicitly to close.

this can't be done from client side until and unless web server supports and thus respond with "Connection : Alive" instead of "Connection : closed" client can only request to keep alive the connection, but final decission is taken by web server.

Originally posted by Deepa Raghuraman:
hi,
Can u tell be how to upgrade HTTP1.0 to HTTP1.1?

just use higher version of jdk like 1.4 to make java.net.URLConnection , thats all.



[ May 03, 2002: Message edited by: gautam shah ]
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Deepa Raghuraman:
In java.sun.com site, i read that HTTP1.0 by default has Connection : close which can be made presistance connection using Keep-Alive and HTTP1.1 by default has Connection : keep-alive.
According to ur reply,HTTP1.0 closes the connection after each request and keep-alive cannot be used in it.
Although the HTTP 1.0 specification (RFC 1945)did not specify a keep-alive feature, some (but not all) servers did implement an experimental version. According to RFC 2068 19.7.1 these implementations were faulty, and if you want keep-alive you should really be using a HTTP 1.1 server and client.
- Peter
Deepa Raghuraman
Greenhorn

Joined: Nov 26, 2001
Posts: 13
hi,
how would i know which version of HTTP I am using.Is there any method which specific the HTTP version? As u mentioned using higher version of Jdk i.e., 1.4 I can have HTTP1.1. But when
I mention HTTP/1.1 the server responsed as "server cannot under the request sent by the HTTP1.1 client and the hostname is missing. I had pass the Host header along with the request. I am using JDK1.4.
thanks in advance,
Deepa Raghuraman
 
Consider Paul's rocket mass heater.
 
subject: Problem in URL Concept(need help urgently)
 
Similar Threads
Doubt in HTTP
HTTP connection
friends can any one tell me what is mean by Persistant Http connection
connection pooling
Checksum file download?