### Navigation

- index
- modules |
- next |
- previous |
- ws4py 0.3.2 documentation »

# Basics

ws4py provides a high-level, yet simple, interface to provide your application with WebSocket support. It simples as:

    from ws4py.websocket import WebSocket

The `WebSocket` class should be sub-classed by your application. To the very least we suggest you override the `received_message(message)` method so that you can process incoming messages.

For instance a straightforward echo application would look like this:

    class EchoWebSocket(WebSocket):
        def received_message(self, message):
            self.send(message.data, message.is_binary)

Other useful methods to implement are:

> - `opened()` which is called whenever the WebSocket handshake is done.
> - `closed(code, reason=None)` which is called whenever the WebSocket connection is terminated.

You may want to know if the connection is currently usable or `terminated`.

### Navigation

- index
- modules |
- next |
- previous |
- ws4py 0.3.2 documentation »