• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet - Servlet Communication

 
Tojosid
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a login page. This form is submitted to a servlet. The servlet has an vector which contains the users who have logged in. Now there is an applet which displays the users logged in. (the above vector is passed to the applet)
The functionality required is that the moment someone logs in the system, his/her name should be reflected in the applet window(which is not workng as of now ). Isn't this a kind of server push? I have to start the applet everytime I want to see the changes.
Any suggestions to make this working? Please help!!!
-sid
[This message has been edited by Tojosid (edited March 13, 2001).]
[This message has been edited by Tojosid (edited March 13, 2001).]
 
Rahul Rathore
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only way for the server to (unilaterally) update an applet is to maintain a direct socket connection with the applet. In your servlet you will need to maintain some Vector of Sockets for connection with each running applets. Whenever a user logs in or logs out, the users Vector will change. Then iterate through the Vector of Sockets, and over each socket, serialize the updated users Vector (using ObjectOutputStream). Retrieve the updated users Vector it in the applet (using ObjectInputStream over the socket).
If you don't want to use sockets or RMI, then you may program the clients to send periodic requests for getting updates. For eg. implement a timer in the applet and using it make periodic update requests to the servlet for getting the users vector. I think this approach would be simple but it has problems. There may be a time-lag before the update to be retrieved by the client. The time-lag may be reduced by reducing the time-intervals between update requests. But then useless network traffic and client/server processing maybe generated because requests will be made even if there is no update.
 
Tojosid
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rahul Rathore:
The only way for the server to (unilaterally) update an applet is to maintain a direct socket connection with the applet. In your servlet you will need to maintain some Vector of Sockets for connection with each running applets. Whenever a user logs in or logs out, the users Vector will change. Then iterate through the Vector of Sockets, and over each socket, serialize the updated users Vector (using ObjectOutputStream). Retrieve the updated users Vector it in the applet (using ObjectInputStream over the socket).
If you don't want to use sockets or RMI, then you may program the clients to send periodic requests for getting updates. For eg. implement a timer in the applet and using it make periodic update requests to the servlet for getting the users vector. I think this approach would be simple but it has problems. There may be a time-lag before the update to be retrieved by the client. The time-lag may be reduced by reducing the time-intervals between update requests. But then useless network traffic and client/server processing maybe generated because requests will be made even if there is no update.

Thanks Rahul for yor suggestions. But the thing is that I am using URL connection for the communication. Can youu suggest some method other than refreshing the applet window (which i am doing at the moment and its working)???
Are there any listeners?? or how about using observer and observable classes??
Thank you for your suggestion ...in advance.
sid
 
Stephanie Grasson
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sid,
Please register with a proper name. "Tojosid" does not follow the conventions. See here for details: http://www.javaranch.com/name.jsp
If you do not register properly, your account will be disabled. I would hate to see that happen.
Thank you.
Stephanie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic