[Last Call] Learn how to a build a cloud-first strategyRegister Now


Basic Chat application on web with Ajax

Posted on 2007-07-24
Medium Priority
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
  • 2
LVL 63

Accepted Solution

Zvonko earned 1500 total points
ID: 19554270
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 http://www.fiddlertool.com


Author Comment

ID: 19599128
I try fiddlertool but nothing seems on action
LVL 63

Expert Comment

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


Expert Comment

ID: 24951006
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month18 days, 2 hours left to enroll

830 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