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:
- A
Routerto render the web page - A
WebSocketwith theChathandler - A
Routerwith theRpchandler for exposing a JSON-RPC api.
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('http://127.0.0.1:8060/rpc')
>>> p.message('Hi from rpc')
'OK'
This example uses the pulsar Publish/Subscribe handler to synchronise messages in a multiprocessing web server.
Implementation¶
-
class
examples.chat.manage.Chat(pubsub, channel)[source]¶ The websocket handler (
WS) managing the chat application.-
pubsub¶ The publish/subscribe handler created by the wsgi application in the
WebChat.setup()method.
-
-
class
examples.chat.manage.WebChat(server_name)[source]¶ This is the wsgi application for this web-chat example.
-
setup(environ)[source]¶ Called once only to setup the WSGI application handler.
Check lazy wsgi handler section for further information.
-