Closed ptdecker closed 1 year ago
You theory does not really agree with the logs that you are showing.
First of all, there is no Socket.IO here. Your server (Flask-Sock) uses WebSocket, and your client (the websockets package) also uses WebSocket. This is fine.
The ConnectionError
exception that you are getting is only used when your web server is the Flask development web server. This is a long story, but to make it short, the Flask development web server has been proven difficult when a route upgrades to WebSocket. Newer releases of Flask and Werkzeug use this ConnectionError
exception as an attempt to end the WebSocket call gracefully. On older versions of these packages, the error shows up in the log, but it is still benign, as it just indicates that the connection with the client ended.
So that's it. I really have no indication that there is a problem. When you deploy your application on a production web server, none of this will happen and your WebSocket calls will end cleanly.
Ah, very interesting @miguelgrinberg. Thank you! How this came to light is if debug mode is off resulting in that error not being immediately visible on the server side, the connection from my client stays open for a long time (perhaps 20 seconds or so). That problem is what put me on this path when a very capable coworker of mine couldn't figure it out either and didn't see anything wrong on the surface with my code. This side effect went away immediately when I enable debug mode which led me to then try to find documentation on the "connection error" error. That goose chase took me down the Sockets.IO route and since much of this is new to me, I don't know the difference really. So, you're note goes a long way to explaining it. We can live with that delay on the client side if it goes away in a production setting. Thank you for taking the time to respond. We can probably close this question because of it. I appreciate your help.
I'm only posting this question here because it is unclear where there is a better forum for it. If some other place is better while still avoiding the StackOverflow noise, please let me know and accept my apologies.
I have a situation where we have a Flask server that uses flask-sock for its websocket implementation. I'm trying to build a stand-alone CLI client for it in Python whose purpose, coupled with a server end-point, is to support streaming large files to the server through a websocket.
I thought I had it all implemented, but had one small puff of smoke that turned out to be a fire once I enabled debugging on the server side. I think I learned that the client I was trying to use is a Sockets.IO client and was causing the server to through a connection error at the end of the session. I can send the file just fine, but upon completion I get a 500 connection error on the server. I may have this totally wrong.
I think I pinpointed it to the package I am using on the client (https://pypi.org/project/websockets/).
I've spent so much time on this and at this point am feeling lost being so close to a solution, but yet so far.
Any help would be appreciated. Do I understand the situation? Should I be using a different client? I don't have a choice on the server side.
Below are the server and client apps and the server and client logs when running.
Server:
Client:
Server console:
Client console: