Example: WSGI/Flask (and WebSockets)

demo_app.body_echo()[source]

Echo back the HTTP POST body, verbatim.

demo_app.get_chunks()[source]

Return a series of timestamps with some delay_ms, as HTTP chunks.

demo_app.get_source()[source]

Serve the source code for this app from disk.

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 or 0

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 or 0 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 or 0

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 or 0 is returned, the connection is closed.

demo_app.status_ok()[source]

Status endpoint. We’ll just use this to serve “OK” and as a check that the service is up and running.