httpout supports WebSocket with no complexity for you to use.
The websocket
object will be None
on requests that are not considered a WebSocket type, or the WebSocket support is disabled with --no-ws
.
Example:
# ws.py
import sys
from httpout import run, response, websocket
if websocket is None:
response.set_status(400, 'Bad Request')
print('Not a websocket request')
sys.exit()
async def main():
async for message in websocket:
await websocket.send(f'You said: {message}')
run(main())