Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Servlet-applet communcation  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!