Two Laptop Bag
The moose likes Servlets and the fly likes Unsolicited Responses Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Unsolicited Responses" Watch "Unsolicited Responses" New topic

Unsolicited Responses

Doug Gschwind
Ranch Hand

Joined: Dec 17, 1998
Posts: 44
Suppose you have a web browser/applet running which you would like to receive unsolicited messages from the server side. e.g. Suppose the client side wishes to subscribe for and display event data when certain events are posted to an OMG CORBAservice Event Service implementation.
It does not appear that Servlets support this functional need very well due to the request-response paradigm.
I did however read about a couple of tricks which may or may not in fact help in this regard. One involves the use of a persistent connection. The other could be that the client side issues one request, where the servlet responds multiple times, but never actually closes the response object. What do you know about these two mechanisms?
What technological alternatives provide a more "intended" solution to this problem?
paul wheaton

Joined: Dec 14, 1998
Posts: 20973

I don't see a servlet helping here. I do see a socket connection from the applet to a server program (not a servlet). Over this full time connection, the server will send the occasional message.
This seems the most straightforward.

permaculture Wood Burning Stoves 2.0 - 4-DVD set
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
I agree with Paul here. One of the main things about the Applet specification is that despite all the sandbox limitations, applets are always allowed to make a socket connection to the originating host. It's a bit of a shame, but many applet writers inore this and try to make HTTP jump through hoops.
Don't be afraid of writing a server, either. There are plenty of examples around, and a simple server needn't be more than 50 lines of code.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
g2 bhai

Joined: Jul 11, 2001
Posts: 2
Since the solution is to have an Applet to use for communication between the Server and the client.Can i have an invisible Applet..which will run in the background and only show messages to the client when the Server when the server wants the applet to display the messages.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

Correct. Http doesn't allow for "volunteering" info. However, an applet can poll the server and get the same net effect, subject to the polling overhead. To do a true "listen" (non-polled operation), you'd need to use a non-http I/O port, which could run you into the firewall.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Unsolicited Responses
It's not a secret anymore!