wood burning stoves
The moose likes Servlets and the fly likes Servlet-applet communcation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet-applet communcation" Watch "Servlet-applet communcation" New topic

Servlet-applet communcation

Andrey Orekhov

Joined: Nov 29, 2001
Posts: 14
Task - to send unknown number of objects in unknown period of time from server to client (applet)
What are possible ways to implement this task?
I tried 2 approaches, both failed to work:
1) Applet using URLConnection makes request to the servlet. Servlet obtains OutputStream and passes it to the class which will later send objects through the client.
Doesn't work, as output stream seems to be closed after servlet doGet() method returns
2) Applet creates ServerSocket which listens for incoming requests on specified port. Then applet makes request to the servlet. Servlet obtains remote hostname and passes it to the class. This class creates socket and sends object through it when when such necessity arises
Doesn't work as ServerSocket cannot be instantiated (constructor throws exception)
Please let me know if better approach exists or if my approaches are correct or not
Thank you
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
The simplest thing would be to have the applet contact the servlet and retrieve one or more objects in a single request-response cycle. To determine if any new data is available you might be able to do a HEAD request first and have the servlet return a date-last-modified header that would indicate when new objects were available and should be downloade.
I imagine the attempt to open a ServerSocket on the applet side ran into a security exception since opening arbitrary sockets on the client side is a security risk. You might be able to do this if you signed the applet.
I agree. Here's the link: http://aspose.com/file-tools
subject: Servlet-applet communcation
It's not a secret anymore!