Jump to content

How to send data to the client side without the client side having to ask for it


clumsygenius

Recommended Posts

Lets say you want a little exclamation mark to appear next to mail logo of the page to let the user know that they have new mail. you want this to automatically pop up when they get mail without them having to refresh.

 

I KNOW I can use Ajax to periodically send requests to the server and check for new mail. but I was wondering if there is a way to make the client side just listen, and have the server send it an update whenever new mail comes in.

 

Thaks

Link to comment
Share on other sites

What about in the case of instant messengers like the one in gmail or facebook? when a message a sent, the recipient receives it within a second. So does client side script send requests multiple times a second to check for new incoming instant messages? that seems a little wasteful.

Link to comment
Share on other sites

What about in the case of instant messengers like the one in gmail or facebook? when a message a sent, the recipient receives it within a second. So does client side script send requests multiple times a second to check for new incoming instant messages? that seems a little wasteful.

 

AJAX. Wasteful? Not really. In the case of an IM app, the AJAX request itself is insignificant. It probably only needs to sent the ID of the conversation and the ID if the user. If there is no new content (as would be the case in 99.99% of the requests) the server would simply return a false value (i.e. a zero) or maybe a little other info. That would take a whole whopping single bit of data. An email client would be no different. It is only when there is new data that any significant data would be returned, which is what you want anyway. It *may* be wasteful on the server, which is why you would write the code to be as efficient as possible. But, that is also why services like Google have thousands of server to support their products.

 

If you want to validate all of this for yourself. Download an app called Fiddler. It is a little complicated to use, but it will show you all incoming/outgoing transmissions from your computer. With it I'm sure you will be able to see the multiple AJAX calls that are taking place.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.