Websocket Chat Server

The code for this example is located in the examples.chat.manage module.

This example is web-based chat application which exposes three different wsgi routers:

To run the server:

python manage.py

and open web browsers at http://localhost:8060

To send messages from the JSON RPC open a python shell and:

>>> from pulsar.apps import rpc
>>> p = rpc.JsonProxy('')
>>> p.message('Hi from rpc')

This example uses the pulsar Publish/Subscribe handler to synchronise messages in a multiprocessing web server.


class examples.chat.manage.Chat(pubsub, channel)[source]

The websocket handler (WS) managing the chat application.


The publish/subscribe handler created by the wsgi application in the WebChat.setup() method.

on_message(websocket, msg)[source]

When a new message arrives, it publishes to all listening clients.


When a new websocket connection is established it creates a new ChatClient and adds it to the set of clients of the pubsub handler.

class examples.chat.manage.Rpc(pubsub, channel, **kwargs)[source]
rpc_message(request, message)[source]

Publish a message via JSON-RPC

class examples.chat.manage.WebChat(server_name)[source]

This is the wsgi application for this web-chat example.


Called once only to setup the WSGI application handler.

Check lazy wsgi handler section for further information.