Reputation: 5853
Python 3.7 on windows
When running the sample from quart
from quart import Quart, websocket
app = Quart(__name__)
@app.route('/')
async def hello():
return 'hello'
@app.websocket('/ws')
async def ws():
while True:
await websocket.send('hello')
app.run()
When running http://127.0.0.1:5000/ws, got
Bad Request Bad request syntax or unsupported method
Upvotes: 1
Views: 744
Reputation: 5074
You need a JS client to connect to the WebSocket, not just your browser. Let's call it test-ws.html :
<!DOCTYPE html>
<html>
<body>
<script>
let socket = new WebSocket("ws://localhost:5000/ws");
socket.onmessage = function(event) {
alert(`Data received: ${event.data}`);
socket.close();
};
</script>
</body>
</html>
(use python3 -m http.server and go to http://127.0.0.1:8000/test-ws.html to test it in your browser)
Upvotes: 2