Houdini 20.5 hwebserver

hwebserver.WebSocket class

Base class for WebSocket support with the embedded server.

On this page

This class is the base class for all websocket support in Houdini’s embedded server.

Note

WebSocket support is Python3 only.

Setup

On its own the WebSocket class cannot do much of anything. The class must be registered with the server so that incoming Upgrade: websocket requests can create an instance of the class and hand off the handling to the websocket instance. To install the instance the decorator can be used to install the websocket.

Example

The below example will echo back anything sent from the client. This websocket will be used anytime a client sends a HTTP upgrade request on path /echo.

@webSocket("/echo")
class WebSocketEcho(hwebserver.WebSocket):
    async def connect(self, req):
        await self.accept()

    async def receive(self, text_data=None, bytes_data=None):
        # Send message as text data
        await self.send(text_data)

Methods

See also

hwebserver

Classes

Starting and Stopping

Handling Web Requests and Returning Responses

WebSocket

  • WebSocket

    Base class for WebSocket support with the embedded server.

  • hwebserver.webSocket

    Decorator for registering WebSocket classes with Houdini’s web server.

API Calls

  • hwebserver.apiFunction

    Decorator for functions that can be called through an API endpoint on Houdini’s web server, returning JSON or binary responses.

  • hwebserver.APIError

    Raise this exception in apiFunction handlers to indicate an error.