Example: WSGI/Flask (and WebSockets)¶
- demo_app.get_ws_index()[source]¶
Serve back a very basic HTML page with some embedded JavaScript that uses the WebSockets API.
- demo_app.headers_handler()[source]¶
Send the received HTTP request headers back as a JSON dictionary.
- demo_app.on_close(ws)[source]¶
Invoked after a websocket disconnect.
- Parameters
ws – the yimmo.WebSocket connection
Return values are ignored. Any exceptions raised are swallowed and ignored.
- demo_app.on_message(ws, msg, flags)[source]¶
Invoked when a message is received.
- Parameters
ws – the yimmo.WebSocket connection
flags – WebSocket message frame flags
- Returns
on success,
None
or0
- Returns
on failure, a non-zero integer to set
errno
- Returns
any other return value is interpretted as “failure”
If an exception is raised or anything other than
None
or0
is returned, the connection is closed.
- demo_app.on_open(ws)[source]¶
Invoked when a new websocket connection is established.
- Parameters
ws – the yimmo.WebSocket connection
- Returns
on success,
None
or0
- Returns
on failure, a non-zero integer to set
errno
- Returns
any other return value is interpretted as “failure”
If an exception is raised or anything other than
None
or0
is returned, the connection is closed.