CodeCanyon

realtime data polling

3524 posts
  • Australia
  • Bought between 100 and 499 items
  • Community Superstar
  • Exclusive Author
  • Has been a member for 2-3 years
  • Interviewed on the Envato Notes blog
  • Microlancer Beta Tester
  • Sold between 1 000 and 5 000 dollars
Australia says

Say we have a webpage, and user(s) add data, just plain text. Gets written to db.

What is the best method, for polling the server in realtime and updating a div..

So like a ul li list constantly gets updated, posting new data at top of list and shuffling everything down a line.

I have seen scripts like this, just wondered what is best practice and if anyone has any demo or links. This isnt something we want someone to do for us, its a little project I am working on.

Need the data to poll once a second, or so. I suppose using json.

Suggestions ?

101 posts
  • Australia
  • Sold between 5 000 and 10 000 dollars
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 1 and 9 users
michaeldale says
Hear is some great information: http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery

I am using a similar method for a chat system. I am sending the chat in a json array.

Updating just a single li item as you suggested is probably better as it will use less data.

The best way though is this: http://cometd.org

Facebook use a similar method for their chat system. Basically instead of polling every 1 second a session is left open on the server. There isn’t a great deal of documentation or easy to use classes though (for PHP that is). So the first method is easier.

3524 posts
  • Australia
  • Bought between 100 and 499 items
  • Community Superstar
  • Exclusive Author
  • Has been a member for 2-3 years
  • Interviewed on the Envato Notes blog
  • Microlancer Beta Tester
  • Sold between 1 000 and 5 000 dollars
Australia says

Hey Michael, thanks.

Great reply. I have been looking at http://www.ape-project.org/ , but to be honest is a bit beyond my scope. Will check out your examples in depth tho :)

Funnily enough this is for and part of an aussie project I have in mind.

101 posts
  • Australia
  • Sold between 5 000 and 10 000 dollars
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 1 and 9 users
michaeldale says

Thanks for that link, it looks very useful.

I think it is crazy that people are using JavaScript for the server side though! But if it works I spose it’s cool.

3524 posts
  • Australia
  • Bought between 100 and 499 items
  • Community Superstar
  • Exclusive Author
  • Has been a member for 2-3 years
  • Interviewed on the Envato Notes blog
  • Microlancer Beta Tester
  • Sold between 1 000 and 5 000 dollars
Australia says

Thanks for that link, it looks very useful. I think it is crazy that people are using JavaScript for the server side though! But if it works I spose it’s cool.

I was amazed with that too, socket.io and html5 storage persistence etc seems the way to go, I just really want to accomplish a very simple task. I dont want to reivent the wheel, but by the same token … Persistent client side -> server connections annoy the crap out of me. So hence I was looking for a server push method.

Kind of : if newData connect to user , echo newData content. Nothing earth shattering.

3524 posts
  • Australia
  • Bought between 100 and 499 items
  • Community Superstar
  • Exclusive Author
  • Has been a member for 2-3 years
  • Interviewed on the Envato Notes blog
  • Microlancer Beta Tester
  • Sold between 1 000 and 5 000 dollars
Australia says

I may have to look at node.js again

by
by
by
by
by