You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/sources/basics.rst
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
Basics
2
-
============
2
+
======
3
3
4
-
ws4py provides high-level, yet simple, interface to provide your application with WebSocket support.
4
+
ws4py provides a high-level, yet simple, interface to provide your application with WebSocket support. It simples as:
5
5
6
6
.. code-block:: python
7
7
8
8
from ws4py.websocket import WebSocket
9
9
10
-
The :class:`WebSocket <ws4py.websocket.WebSocket>` class should be sub-classed by your application to make something sensible with it. To the very least we suggest you override the :func:`received_message(message) <ws4py.websocket.WebSocket.received_message>` method.
10
+
The :class:`WebSocket <ws4py.websocket.WebSocket>` class should be sub-classed by your application. To the very least we suggest you override the :func:`received_message(message) <ws4py.websocket.WebSocket.received_message>` method so that you can process incoming messages.
11
11
12
12
For instance a straightforward echo application would look like this:
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/.
44
-
45
47
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.
46
48
47
-
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.
49
+
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 close the connection once it receives the last sent messages, which length is 175.
48
50
49
51
Finally the :func:`closed(code, reason=None) <ws4py.websocket.WebSocket.closed>` method is called with the code and reason given by the server.
50
52
@@ -60,19 +62,63 @@ If you are using a Tornado backend you may use the Tornado client that ws4py pro
60
62
.. code-block:: python
61
63
62
64
from ws4py.client.tornadoclient import WebSocketClient
65
+
from tornado import ioloop
66
+
67
+
classMyClient(TornadoWebSocketClient):
68
+
defopened(self):
69
+
for i inrange(0, 200, 25):
70
+
self.send("*"* i)
71
+
72
+
defreceived_message(self, m):
73
+
print m
74
+
iflen(m) ==175:
75
+
self.close(reason='Bye bye')
63
76
64
-
The previous example runs exactly in the same way.
0 commit comments