user987055
user987055

Reputation: 1149

http push django comet

I want to make a django server to refresh the content that you approach the database, if the idea is to first make the user see the current contents of the database and as the valley became the new content, this content comes and is placed above the previous content without reloading the page, in another part of the site is to make you change the current content with the new as it gets to the database?

evserver clearer is my choice, but really do not know how and what would be the most simple and efficient?

Upvotes: 0

Views: 989

Answers (2)

leggetter
leggetter

Reputation: 15467

I think you should avoid HTTP Polling. Here's why:

  • if the frequency of the setInterval combined with the number of users on your web app is going to lead to a big resource drain. If you go through slides 9 to 19 in this presentation you'll see some quite dramatic figures for using Push (Note: this example uses a hosted service but hosting your own realtime server and using Push also has similar benefits)
  • between setInterval calls the data displayed in your app is potentially out of data. Using a Push technology means the instant that new data is available it can be push and displayed in your app. You don't want users looking at an app and thinking they are seeing correct information when they are not.

You should take a the following StackOverflow questions:

For Python/Comet see:

I'd recommend you also start considering "WebSockets" as well as "Comet". Most Comet servers now prefer to use a WebSocket connection when possible.

If you'd prefer to avoid installing and managing your own Comet/WebSocket solution then you could use a realtime hosted service which will allow you Push data through them using a REST API and your clients can receive events by embedding a JavaScript library and writing a small about of code to subscribe and receive the event.

Upvotes: 1

Kee
Kee

Reputation: 1366

The steps are quite straightforward:

  1. Write a model to store data in DB
  2. Write a view that will generate JSON-serialized data upon POST request.
  3. Write a template that will contain JavaScript with setInterval() that will proceed AJAX requests to the view and render recieved data. (I'd suggest using JQuery as it's well documented and widespread).

Upvotes: 0

Related Questions