Hi forum,
to use Socket.IO, our server has to use a library called flask_socketio. Its clients will be browsers. They need a Socket.IO implementation, too. Therefore, the index.html that the server distributes includes
<script src="/socket.io/socket.io.js"></script>
The idea is that client will ask server for this JavaScript file and server serves it. Therefore server can be assured that client has a version that is compatible with server.
But in debug, I see a
127.0.0.1 - - [24/Feb/2021 16:19:34] "GET /socket.io/socket.io.js HTTP/1.1" 400 -
every time I update the browser.
What I have tried:
So I implemented a route
@app.route('/socket.io/<sth>')
def ServeSocketIoClientImplementation():
return render_template("socket.io.js")
It doesn't seem to work.
How is flask-socketio supposed to deliver the client SocketIO implementation?
*** UPDATE ***
I have two working versions (well, kind of):
1)
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script>
This one works, but needs an internet connection which is not desirable in the target environment.
2)
<script src="{{ url_for('static', filename = 'socket.io.js') }}"></script>
The
socket.io.js file is in a subdirectory "/static/socket.io.js" of my python-flask-socket.io program. It doesn't require internet access, but doesn't use WebSocket apparently and falls back to long polling instead.
How can I combine local availability with the use of WebSockets under Socket.IO?