-
Notifications
You must be signed in to change notification settings - Fork 222
Q: First, I have trouble distinguishing the different ways to subscribe/publish (session, group, user, broadcast). For instance, if I want to create several chat rooms, each user possibly connected to one or several chat rooms, what kind of subscription should I use ? For now, I have a server-side dictionary storing all users connected to each room, and when I want to send a message to every user of a given room, I do something like RedisPublisher(facility='foobar’, audience=connected_users[room_id]). This is probably not the good way to do it, I think I missed something in the way I should use your API. A: Currently it is not possible to create rooms with arbitrary users being members. This would be a useful feature.
Q: I am trying to understand the organisation of your project, but I am not familiar with this kind of thing. I understand (I think I do at least) that websocket.py defines the protocole at WS level, handling the reading of the byte stream etc. I also get subscriber.py and publisher.py. What I don’t get is :
- where is the main loop (if there is some) listening for new messages ?
- where is the socket-level relative code ?
- where are the handlers for connection/disconnection/new_message and which function calls them
A:
websocket.py
indeed is the class wrapping the raw protocol. It has been pilfered from another project and unfortunately the only file not running with Python 3. A1: The main loop is insideWebsocketWSGIServer.__call__
. Note that a client connecting via the WS protocol remains in that loop forever. Only until he leaves the page containing the connecting Javascript code, this main loop is exited, normally via a thrown exception. A2: This is done inWebSocketRunServer.upgrade_websocket
oruWSGIWebsocketServer.upgrade_websocket
depending on the mode. Please refer to Roberto's talk at PyCon 2013 for details. A3: This is done inside the main loop. Check forrecvmsg
andsendmsg
. They refer to messages received through the websocket or via Redis.
Q: How can I receive messages that were sent from client (Javascript) using ws protocol? In the given chat example messages are received through standard HTTP protocol using POST method.