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?

7 Comments

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

    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&hellip

    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.

  • 3  |  December 7th, 2006 at 10:07 am by Borat&hellip

    Think I will follow Jdog and try to some code changes to implement chat rooms that allow for more than 2 users. Maybe a admin page too, to be able to do some changes at a higher level.

    Been looking for free Java Chat code to use for a client project, but without any luck so far. I’ll let u know how it goes…

  • 4  |  October 7th, 2008 at 7:15 pm by werutzb&hellip

    Hi!

    I would like extend my SQL knowledge.
    I red so many SQL books and would like to
    read more about SQL for my work as db2 database manager.

    What would you recommend?

    Thanks,
    Werutz

  • 5  |  August 23rd, 2009 at 9:28 pm by Autos&hellip

    I read and feel like home. Thanks to the creators for a good blog!

  • 6  |  September 28th, 2009 at 1:35 am by Georgi&hellip

    Pleasant, sitting at work. Can break away from this tiresome work. Relax, and read the information written here

  • 7  |  December 25th, 2009 at 4:10 am by Webilet&hellip

    I read on the site positive feedback about your resource. Do not even believe it, but now convinced personally. It turns out I was not deceived.

Calendar

September 2006
M T W T F S S
« Aug   Dec »
 123
45678910
11121314151617
18192021222324
252627282930  

Most Recent Posts

Feeds


Links

Subscribe

Social Bookmarks