0

I've been trying websocket-client and socketio-client with no luck so far. The broad picture of what I want to accomplish is this:

Currently, I have a Flask Rest API that has both a web front-end and a command line interface, and it handles several different sets of file uploads/downloads. Both communicate with the server using HTTP requests, the web one from JQuery AJAX and the CLI uses python requests. I would like to switch to using sockets so that database changes from one client appear on all of them. I have been able to get Flask-SocketIO working between my JQuery and Flask server, but I'm struggling with getting any client libraries working from the CLI portion. Is there an easy to use python library for sockets similar to requests I should be using for this transition, or am I going in a totally wrong direction with making this switch?

Another option, unsure of the viability, would be to try and keep both the REST API for the CLI and have sockets for the web interface. Sounds very messy though.

  • https://github.com/nabinkhadka/Flask-SocketIO-Chat – Nabin Aug 09 '17 at 05:33
  • Also for updating clients I have answer here in summary and have necessary link to get jump started https://stackoverflow.com/questions/45486960/what-is-the-best-way-to-update-all-clients-when-flask-database-changes-without-p/45487518#45487518 – Nabin Aug 09 '17 at 05:34
  • Yeah so I have the web side all working, it's the CLI connection to the API I'm having trouble getting to work. I've tried the two client libraries listed at the top with little success. I get the feeling my overall approach is in the wrong direction here, and was hoping to try to understand at a high level what the best approach would be to switch the REST API to using socket connections from both a webapp and command line tool. – I_dont_remember Aug 09 '17 at 14:11

1 Answers1

1

After doing a lot of searching and messing around with various libraries, the one that was easiest to get up and running connecting a command line tool with a Flask-SocketIO webapp was socketIO-client.

This repository came in handy for the issues where I was struggling to understand how to correctly use the waits to receive info on the client side.

Once I've finished the project in a few weeks, I will come back and add more details so people finding this in the future can have an easier time getting this set up.