Re: is using applet-servlet communication to implement realtime
features possible?
On Sun, 17 Jun 2007 16:57:25 +0800, tony wrote:
I'm on a stock(i.e. securities) project. I have an applet showing the
current prices of the stocks and as required, the applet communicates
with servlet and servlet accesses database. Whenever prices changed,
messages should be sent to the applet.I use triggers to do the
database->servlet part, but how can I do the servlet->applet part? As
far as I know, servlet responses if and only if a request comes to it.
So is that possible?
Thank you!
There are three ways to get information from A to B:
1. A opens a socket to a port on B and sends its data.
2. A communicates to B via an already-open socket.
3. B continually polls A for new information, downloading any that comes
its way.
Under the applet security model, #1 is probably impossible; #2 is (as far
as I know) impossible without really ignoring the HTTP specification,
which leaves #3 as the most viable option.
If you want to try method 2, you would have to have a server instance
running that injects data onto a mutually-agreed-upon port that would
probably not be a servlet instance. I don't know how servlets work, but a
persistent connection that allows you to send data down the pipe only
every once in a while (set Content-Length to some really large number and
send batches?) would be the method as to how its done.