How does one typically solve the problem of having a server pushing events to an applet through HTTP? I am trying to avoid making the applet poll the server for events.
I am wondering if it is possible for an applet to open a socket and listen on a port after it has been downloaded onto the client machine. My guess is NO, cuz otherwise a malicious applet could just use up the client's machine network resources.
In the case of stock streamers, I suppose the server must have some way to push events to the applet through HTTP (to work across firewalls). Any idea how this is done in a scalable fashion?
Originally posted by Victor Ho:
I am wondering if it is possible for an applet to open a socket and listen on a port after it has been downloaded onto the client machine.
Sure you can, but it can only connect to the server it was downloaded from.
I suppose the server must have some way to push events to the applet through HTTP (to work across firewalls).
HTTP is a bad choice for a protocol for what you want to do because it is a request-response protocol. You want a persistant connection.
Firewalls typically block incoming connections so there should be no problem connecting back to a server.
You've got a chat applet and lets presume 10 ppl are logged on to the same chat server. Now, when one person writes a message and sends it to the server, the server simultaneously sends it to the other 9 applets. Use a simple TCP/IP connection. As Joe said, HTTP is a bad choice and try avoiding it unless impossible. You may use a thread and make it sleep before firing the next event, although it might be tricky to use with a chat server. Well, the server socket can wait till it recieves a prompt. You can make the applet to behave as a server and a client simultaneously.
Here's what i suggest -
Let the applet load and send the user's ip address to the server. This is on port 4001 (say). Now, the server, using another thread, behaves as a client and opens connection with the applet which now behaves as a client on port 4002(say, not 4001). So now u've got a two way connection. Both the applet and server have got a ServerSocket running to wait for the other to prompt it.
Got it. Simple, huh?