platypush.backend.websocket

class platypush.backend.websocket.WebsocketBackend(port=8765, bind_address='0.0.0.0', ssl_cafile=None, ssl_capath=None, ssl_cert=None, ssl_key=None, client_timeout=0, **kwargs)[source]

Backend to communicate messages over a websocket medium.

Requires:

  • websockets (pip install websockets)
__init__(port=8765, bind_address='0.0.0.0', ssl_cafile=None, ssl_capath=None, ssl_cert=None, ssl_key=None, client_timeout=0, **kwargs)[source]
Parameters:
  • port (int) – Listen port for the websocket server (default: 8765)
  • bind_address – Bind address for the websocket server (default: 0.0.0.0, listen for any IP connection)
  • ssl_cert (str) – Path to the certificate file if you want to enable SSL (default: None)
  • ssl_key (str) – Path to the key file if you want to enable SSL (default: None)
  • ssl_cafile (str) – Path to the certificate authority file if required by the SSL configuration (default: None)
  • ssl_capath (str) – Path to the certificate authority directory if required by the SSL configuration (default: None)
  • client_timeout – Timeout without any messages being received before closing a client connection. A zero timeout keeps the websocket open until an error occurs (default: 0, no timeout)
notify_web_clients(event)[source]

Notify all the connected web clients (over websocket) of a new event

run()[source]

Starts the backend thread. To be implemented in the derived classes if the loop method isn’t defined.

send_message(msg)[source]

Sends a platypush.message.Message to a node. To be implemented in the derived classes. By default, if the Redis backend is configured then it will try to deliver the message to other consumers through the configured Redis main queue.

Parameters:
  • msg – The message to send
  • queue_name – Send the message on a specific queue (default: the queue_name configured on the Redis backend)