How to tie the event listener to the client?

Welcome. Organize a chat(conversation) in django. I would like to know as messengers, etc accept the message without ajax(page does not send and does not take requests every 2 seconds). As messages arrive instantly? How to organize a client listener on the side of the user and on the server of the sender, not to score a endless Ajax request? Please help.
July 2nd 19 at 18:56
1 answer
July 2nd 19 at 18:58
You need to use either AJAX or sockets. If you don't want to bother with sockets, use long polling. Scheme:

  1. A request is sent to the server.
  2. The connection is not closed by the server until a message appears.
  3. When the message appeared – the server responds to the request, mailing.
  4. The browser then makes a new request.

Works well via AJAX. For more details, see here

Find more questions by tags AJAXDjangoPythonjQueryXMPP