Basic Chat application on web with Ajax

Posted on 2007-07-24
Last Modified: 2010-04-16
Hi all,

I want to add a simple chat functionality between online user on my site. I use c# at server side. I currently hold online user list on a table in db and show who is online on the page. I update this list every two minutes by Ajax. I wrote a easy to use ajax javascript code. Here I want to learn How to make messaging between two online users.

The first thing that come in to mind is
on page, check for current user has new message by ajax with a interval one second. And pass his/or her message to server with a send message function.  But this makes really so many request as the online user numbers grow up. And it also will harm explorer at client side as if he/or she talk to many users.  

Is there any other possible methods to send message from server to client without a request taken. Or simple how goggle make chat from gmail page. I like smthg like that. I do not want to use or copy a know code to my project. So do not refer any open source project, only tell me about methods that could be available and give explanatory code examples.

Question by:karanba
    LVL 63

    Accepted Solution

    The polling for updates does not mean that you request for the complete last state message and compare on client side. The better strategy is to get together with the state also some kind of state stamp, for example milisecond time stamp. So at next second polling you ask only wether that time stamp changed. If that change occur then you can ask for complette message text. The stamp request are only few bytes every second.

    To see how google mail is doing that polling you can look at the message flow by using


    Author Comment

    I try fiddlertool but nothing seems on action
    LVL 63

    Expert Comment

    Did you install Fiddler2?
    For https like gmail you need Fiddler2.
    Then you will see the polling in the fiddler window.


    Expert Comment

    Hi Zvonko, I am sure your solution helped Karanba and now I am in the exact situation and trying to come with my own chat system between all the users currently online on my application.

    I would appreciate if you can guide me how to go about it and get it accomplished. I dont have a messaging system in place as of now and am wondering how to start the communication between the users though I can see the online users.

    Please help.


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Article by: DanRollins
    This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
    The viewer will learn how to dynamically set the form action using jQuery.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now