X
X
Xymis2020-10-06 13:32:35
Flask
Xymis, 2020-10-06 13:32:35

What is the best way to build client-server communication in a chat?

At this stage, I wrote the main part of the backing of my little pet-project, I have never developed a chat before, so while I'm thinking about the architecture, I'm throwing a front. I ask for your help in this task
At the moment I have a js timer that every few seconds throws an ajax request to a certain flask-route, from which json is returned with information about the presence of new messages in the chat or their update / deletion. But I understand that such an idea is not good.
The only option that comes to mind so far:
Instead of a timer, throw an ajax function into an infinite loop, send a request to the server and wait for a response, and the answer will not come immediately, but only when the callback for changes in the chat is triggered. Is this idea correct? If not, what should you pay attention to?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2020-10-06
@Xymis

Take websockets and replace flask with an asynchronous framework, a bunch of them.

V
Vladimir Korotenko, 2020-10-06
@firedragon

What you described is longpooling. It works. The same applies to continuous polling, as well as websockets. Each technology has advantages, for example, you can select all ports on the server and there are 65000 of them, so think

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question