This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet-applet communcation" Watch "Servlet-applet communcation" New topic
Author

Servlet-applet communcation

Andrey Orekhov
Greenhorn

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
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
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.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet-applet communcation