Question

I want to dynamically updating a part of a web page for all users on it when I chose to (through a seperate page).

The scenario I'm thinking of:

  1. Say there's a chat box and a picture on a page.
  2. When I click a button on another page (or the same), the picture changes to an embedded youtube video for all users on the page chatting.

What's the best/easiest way to do this?

Was it helpful?

Solution

You'll either need the client to poll (i.e. regularly make AJAX requests to the server to check for changes) or use Comet: basically a long-lived request which keeps an open connection to the server, and the server only returns either to let the request time out (at which point the client makes another request) or there's a change.

Note that if you do this with a popular site, you will need to be able to cope with a lot of simultaneous connections. The "one thread per connection" approach really sucks if you need to have ten thousand connections at a time. You'll want to be able to serve those requests asynchronously, basically. How you achieve that will depend on your server platform.

OTHER TIPS

I would not be using 'Comet'.

It is almost certainly not neccessary for this update to be immediate across all people viewing the website.

To be perfectly honest I'd probably sneak this update it when you update whatever other data they are updating (say, the chat logs). Thus you'd just mark the video as the 'next' live item for that segment, and the code already updating the chatting would change that value if it noted it needed a new one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top