Chat Applet Communicating with a Servlet

September 11th, 2006

When coding a Chat application in Java that should be available on the Web a good choice is to have an applet communicating with a servlet.

Although sockets can be used, a better alternative is to use a high-level connection with HTTP. This will work even for applets running behind firewalls since most firewalls allow HTTP connections. The applets are simply used as browsers sending messages with the POST method and retrieving messages with the GET method.
Because HTTP is a unidirectional protocol, and a chat user of course should be able to see incoming messages at once, bidirectional communication has to be simulated. This is done by having the applets continuously poll for new messages. There will be some overhead of course, but unlike more common CGI programs a servlet no longer has to wait as the server launches a CGI program to handle each of its repeated requests.

Here is a description of a Chat Applet / Servlet application I’ve created which I modestly named: Magnificent Chat: Applet/Servlet Communication.
At the bottom of the description page you can download the .java files and try out a working example.

Entry Filed under: Java

Bookmark with del.icio.us

Digg it?

2 Comments

  • 1  |  November 15th, 2006 at 2:18 pm by Jdog

    Just got the chat up and running in my lan. Works great! Planning on redoing your PrivateDialog class to implement the behavior of chat rooms. I might be sending a few mails if I get stuck, if it’s ok?

  • 2  |  November 21st, 2006 at 11:48 pm by Martin

    Had some thoughs on implementing chat rooms myself, but I haven’t got the time…yet.

    Sure, send me a message if you get stuck. Either use my contact page or send me a mail. Good luck.

Links

Subscribe