How to implement individual chat SocketIo Flask?

Write social.network. How to implement chat between users of the tete-a-tete? More precisely: there is a url: user/ - user page, chat there. When sending the request using socketio in js, I can specify the url of the specific user ("{{ url_for('user', id_user=user.id) }}"). On the server side in flask as I need to register the namespace to the query from the page Pogo user came to Nый socket? If you register a namespace owner (user/2) then it works, but , of course only for the second user. Whether it is possible to do so? The alternative is to make a separate url (/chat) which will go to all messages from all users. In the message to send id of the sender to get from the database all messages from this sender, and return the array. Kind of reluctance)
April 4th 20 at 00:32
1 answer
April 4th 20 at 00:34
Solution
Implemented in the following way: Js 2 creates the socket connection (c URLs /chat {{ url_for('user', id_user=user.id) }}. Socket /chat only sends the socket {{ url_for('user', id_user=user.id) }} only accepts the responses from the server. On the server, only one function @socketio.on('message') - writes to database and returns 2 answer:
send(..... namespace = url_for('user', id_user=audiodevices)
send(.... namespace = url_for('user', id_user=idiolectal).
Audiodevices and Idiolects are sent via socket to the client along with the message.

Find more questions by tags JavaScriptSocketsFlaskSocket.io