Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Pushing response back to a client  RSS feed

 
Jon Kidd
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably a no-brainer question here for you all but I am writing a very simple chat (yes, another one...) application. Basically I just want it to be all 1-1 based via a servlet on the server.
So a client initiates a conversation with another user and each response gets pushed into each others text area.
I understand the mechanics of it simply enough but am having trouble understanding how to push the response back from the servlet on the server to the applet on the clients PC without them needing to refresh ?
As I said, probably very easy but any help in the right direction would be much appreciated.
Thanks everyone,
Jon
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think the web page with the applet needs to be refreshed in order to see the data transmitted from the server to the applet. As long as the connection is opened between the server and the applet, the applet should display the data sent to it as soon as it is sent.
Disclaimer: I have not done any chat apps and therefore I may be missing something...
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tony Alicea:
I don't think the web page with the applet needs to be refreshed in order to see the data transmitted from the server to the applet. As long as the connection is opened between the server and the applet, the applet should display the data sent to it as soon as it is sent.
Disclaimer: I have not done any chat apps and therefore I may be missing something...

That's only true if he's not using http tunnelling or some other reactionary protocol. You can't "push" HTTP, after all.
An applet running a 2-way protocol would need to repaint its display area or place the returned data in some sort of control that would update its own little corner of the display, same as in any ordinary Java applet - the fact that the data came in from the wire is irrelevant.
 
Sudd Ghosh
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm curious to know why for HTTP protocol there is no better way than passive polling on some field? By better way, I mean some active notification mechanism that one can use to implement the "push" mechanism ?
Suppose I am writing a mission-critical network monitoring application, where I want to refresh actively because any passive polling may cause some time delay, which I can't afford. How can one do this kind of thing with the HTTP request/response structure ?
Thanks.
 
Mitan Chandihok
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sudd,
Well HTTP is a stateless protocol, basically its like this, the client (browser) asks a question, and the server (Web Server/App Server) answer the question back. It does not remember any previous communication nor does it talk back when not being spoken too.
Using HTTP for an application like u described would not be able to work without an auto-refresh built into the HTML because you would need to tell the server to reanswer your question.
Hope that explains some stuff.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!