Currently, I have a dynamic website that runs on Flask and I'd like to implement a chat client in the back-end that utilizes websockets that will connect to an external server. So, for example, I'd like to start a websocket to this external chat server when the logged-in user visits the "/chat" route.
Then, I'll handle sending/receiving messages with JavaScript on the page that POSTs a JSON object to another route, such as "/send_msg" while constantly checking for new messages by GETing from "/receive_msg".
The problem is that every single tutorial I've seen on the web (including questions on SO) have been about local websockets where the flask app itself acts as a chat server. And using python's built-in socket module is no good (I think) because I don't see a way to keep it open while the user is on the page and then close()-ing it when the user leaves the page. Is there any way to do this for an external server at all? If so, how do I go about doing this? Thanks! <3