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
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...
Tony Alicea Senior Java Web Application Developer, SCPJ2, SCWCD
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.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
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.
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.