Skip to content

Commit 0af1f14

Browse files
committed
manager doc
1 parent 38ec5d2 commit 0af1f14

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

docs/clienttutorial.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@ An example is better than any word so let's have a look at a basic client:
4242
4343
This example demonstrates how to implement a client, here based on a thread-model, that is able to send and receive messages from a connected endpoint at ws://localhost:9000/.
4444

45-
In this snippet, when the handshake is successful, the :func:`opened() <ws4py.websocket.WebSocket.opened>` method is called and within this method we immediatly send to the server a bunch of messages. First we demonstrate how you can use a generator to do so, then we simply send strings.
45+
In this snippet, when the handshake is successful, the :meth:`opened() <ws4py.websocket.WebSocket.opened>` method is called and within this method we immediatly send to the server a bunch of messages. First we demonstrate how you can use a generator to do so, then we simply send strings.
4646

4747
Assuming the server echoes messages as they arrive, the :func:`received_message(message) <ws4py.websocket.WebSocket.received_message>` method will print out the messages returned by the server and simply closes the connection once it receives the last sent messages , which length is 175.
4848

4949
Finally the :func:`closed(code, reason=None) <ws4py.websocket.WebSocket.closed>` method is called with the code and reason given by the server.
5050

51+
.. seealso::
52+
:ref:`manager`.
53+
5154
Tornado
5255
-------
5356

docs/managertutorial.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.. _manager:
2+
3+
Managing a pool of WebSockets
4+
=============================
5+
6+
ws4py provides a :class:`ws4py.manager.WebSocketManager` class that takes care of
7+
:class:`ws4py.websocket.WebSocket` instances once they the HTTP upgrade handshake
8+
has been performed.
9+
10+
The manager is not compulsory but makes it simpler to track and let them run
11+
in your application's process.
12+
13+
When you :meth:`add(websocket) <ws4py.manager.WebSocketManager.add>` a
14+
websocket to the manager, the file-descriptor is registered with the
15+
manager's poller and the :meth:`opened() <ws4py.websocket.WebSocket.opened>`
16+
method on is called.
17+
18+
Polling
19+
-------
20+
21+
The manager uses a polling mechanism to dispatch on socket incoming events.
22+
Two pollers are implemented, one using the traditionnal :py:mod:`select`
23+
and another one based on `select.epoll <http://docs.python.org/2.7/library/select.html#epoll-objects>`_
24+
which is used only if available on the system.
25+
26+
The polling is executed in its own thread, it keeps looping until
27+
the manager :meth:`stop() <ws4py.websocket.WebSocket.stop>` method.
28+
29+
On every loop, the poller is called to poll for all registered file-descriptors.
30+
If any one of them is ready, we retrieve the websocket using that descriptor
31+
and, if the websocket is not yet terminated, we call its `once` method
32+
so that the incoming bytes are processed.
33+
34+
If the processing fails in anyway, the manager terminates the websocket and
35+
remove it from itself.

0 commit comments

Comments
 (0)