What is the easiest way to implement push-push-server behavior for a web page?

I am trying to make a very simple 2-local chat for my Django site. I am learning AJAX for this. I need parts of the web page to refresh without user interaction:

  • When User 1 sends a message, it should appear on the User 2 screen.
  • When user 1 logs out, his status should change to "offline" on the screen of User 2.

What is the easiest way to implement this? Do I need to use JavaScript to regularly poll the server? If so, what is the best practice for this? I found several solutions about using setInterval or setTimeout, but was not sure if this is the best way.

(I read the reverse of AJAX, but from what I read, it's harder to implement. I don't need my solution to be fast or scalable, I just need to work it.)

+4
source share
3 answers

Since you said that Comet is not important to you, which admittedly is not very easy to get, setInterval will do the trick. However, you want to be smart. You should probably start with an interval of 30 seconds. If the user starts chatting, your interval should go down to 5. When you notice less and less activity, your timer should again drop to 30 seconds and so on. He is not going to win any scalability agreement awards, but it will be done for your medium-sized mid-sized website.

For more on this method, check out this related question .

+3
source

Take advantage of Orbited . At first glance, it's easy to look around, start mumbling about being too complicated, but once you get through it, you will understand what โ€œbest practiceโ€ is and why it is both fast and scalable.

You will also realize that this is an outstanding method and can be used for a large number of dynamic web pages.

+2
source

Another option that will meet you halfway is WebSync On-Demand (or any other hosted comet service ... not sure if there are others). This will allow you to realize the capabilities of the push-push server, but it's nice and easy to work, since all you need to do is enable the javascript client.

0
source

All Articles