Closed tshmit closed 1 year ago
The 404s occur because your client is trying to connect via the Socket.IO protocol, not WebSocket. You seem to be mixing the two protocols here. If you want to use Socket.IO then use a Socket.IO client and the Flask-SocketIO extension. If you want to use plain WebSocket, then use a WebSocket client and the Flask-Sock extension.
Thanks for your reply, Miguel.
Sorry, I guess I'm confused. Is this line (# 19 in index.html, above), not using the WebSocket you refer to?
const socket = new WebSocket('ws://' + location.host + '/echo');
What I mean is that you have some other client running in your computer making requests like these:
127.0.0.1 - - [01/Mar/2023 10:05:28] "GET /socket.io/?EIO=4&transport=polling&t=OQTjFdZ HTTP/1.1" 404 -
Of course, you are right. I'd been testing in another browser and forgot about it. It's not yet clear to me why that was preventing the above client code from connecting, but now that I have something running (what a relief) I'll figure it out. Thank you so much for your help!
Hello Miguel, First, thank you for your efforts in creating this package!
I had some trouble with my first try at implementation, with the server returning:
I then created a new test by cutting and pasting code directly from your blog post https://blog.miguelgrinberg.com/post/add-a-websocket-route-to-your-flask-2-x-application and encountered exactly the same behavior :-/
However, when testing with:
wscat --connect ws://127.0.0.1:5000/echo
the server connects as expected.I am testing on a clean environment with only flask and flask_sock being installed:
To confirm I didn't somehow copy/paste incorrectly from your demo, here is the code pasted from my editor: Index.html
And main.py
In my app I did also test the client importing from socket.io on as so:
const socket = io.connect("ws://127.0.0.1:5000/echo
But saw the same result.I'm stumped. Any thoughts on what might be going wrong? Thank you!