Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Persistent HTTP/S connections

843842Sep 19 2008 — edited Sep 20 2008
Howdy all,

I've been trawling the forums looking for a solution to this, but haven't yet found it. Here's what I want to do:

I want to have a client establish an HTTP/S connection to a server (servlet container underneath), and hold the connection open until I explicitly invoke close() on the socket's in/out streams.

On the server, I want the inbound request to be added to a separate thread where it will wait indefinitely for input from the client, and indeed be able to stream data back to the client.

Basically I just want a simple client/server socket connection, but wrapped in SSL and firewall friendly. So client establishes "permanent" outbound connection, which effectively "never" closes.

In my test environment I have a simple servlet which captures the in/out streams from the request/response coming in and attaches them to an object running in a separate thread. The intention is that the servlet will return pretty much immediately, but I can access a "live" connection to the client at a future point in time.

On the client I am using commons http to establish an HTTP connection to the server, and basically wait for data (InputStream.read().. assuming this blocks until data arrives).

The problem is that despite my attempts to set "Keep-Alive" headers in every place but my ear, the connection is closes (presumably by the servlet container) as soon as the servlet exits.

Any way I can retain a persistent HTTP/S connection through which I can send data back and forth whenever I choose?

Cheers.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 18 2008
Added on Sep 19 2008
3 comments
314 views