Skip to content

Commit a2bbb3e

Browse files
committed
moved most of the readme into the main doc for clarity
1 parent db18a6b commit a2bbb3e

File tree

9 files changed

+111
-219
lines changed

9 files changed

+111
-219
lines changed

README.md

Lines changed: 1 addition & 217 deletions
Original file line numberDiff line numberDiff line change
@@ -3,220 +3,4 @@ WebSocket for Python (ws4py)
33

44
Python library providing an implementation of the WebSocket protocol defined in RFC 6455 (http://tools.ietf.org/html/rfc6455).
55

6-
Overview
7-
========
8-
9-
The latest stable release is 0.2.4.
10-
11-
The current development version is 0.3.0-beta.
12-
13-
ws4py does not support older version of the protocol like Hixie-76.
14-
15-
16-
Licensing
17-
---------
18-
19-
ws4py is released under a BSD license.
20-
21-
Platforms
22-
---------
23-
24-
ws4py runs on:
25-
26-
* CPython 2.6+/2.7+/3.2+
27-
* pypy 1.8/1.9
28-
29-
Implementation
30-
--------------
31-
32-
ws4py data model is rather simple and follows the protocol itself:
33-
34-
* a highlevel WebSocket class that determines actions to carry based on messages that are parsed.
35-
* a Stream class that handles a single message at a time
36-
* a Frame class that performs the low level protocol parsing of frames
37-
38-
Each are inter-connected as russian dolls generators. The process heavily relies on the
39-
capacity to send to a generator. So everytime one of those layers requires something,
40-
it yields and then its holder sends it back whatever was required.
41-
42-
The Frame parser yields the number of bytes it needs at any time, the stream parser
43-
forwards it back to the WebSocket class which gets data from the underlying data provider
44-
it holds a reference to (a socket typically). The WebSocket class sends bytes as they are read from the socket
45-
down to the stream parser which forwards them to the frame parser.
46-
47-
Eventually a frame is parsed and handled by the stream parser which in turns
48-
yields a complete message made of all parsed frames.
49-
50-
The interesting aspect here is that the socket provider is totally abstracted
51-
from the protocol implementation which simply requires bytes as they come.
52-
53-
This means one could write a ws4py socket provider that doesn't read from the
54-
wire but from any other source.
55-
56-
It's also pretty fast and easy to read.
57-
58-
Performance
59-
-----------
60-
61-
ws4py doesn't perform too bad but it's far from being the fastest WebSocket lib under heavy load.
62-
The reason is that it was first designed to implement the protocol with simplicity
63-
and clarity in mind. Future developments will look at performances.
64-
65-
Note however that ws4py runs way faster with CherryPy on PyPy than it does on CPython.
66-
And [wsaccel](https://github.com/methane/wsaccel) replaces some bottleneck with Cython implementation for CPython.
67-
68-
Client support
69-
--------------
70-
71-
To its simplest form, ws4py comes with a client that doesn't depends on anything but Python.
72-
It's a threaded client as simple as:
73-
74-
```python
75-
from ws4py.client.threadedclient import WebSocketClient
76-
class EchoClient(WebSocketClient):
77-
def opened(self):
78-
print "Connection opened..."
79-
80-
def closed(self, code, reason=None):
81-
print code, reason
82-
83-
def received_message(self, m):
84-
self.send(m)
85-
86-
try:
87-
ws = EchoClient('ws://localhost:9000/ws')
88-
ws.connect()
89-
except KeyboardInterrupt:
90-
ws.close()
91-
```
92-
93-
ws4py provides also a client based on Tornado and gevent. Strangely enough, Tornado
94-
comes up with a server implementation but not a client. They work in a similar fashion.
95-
96-
Note that ws4py may should run on Android rather well through SL4A (http://code.google.com/p/android-scripting/).
97-
98-
99-
Server support
100-
--------------
101-
102-
ws4py does provides two server implementation. Mostly, servers are only used
103-
for the initial HTTP handshake, once that's done ws4py takes over the socket
104-
and the server isn't required any longer aside from managing the WebSocket instance
105-
itself.
106-
107-
ws4py implements the server side through:
108-
109-
* CherryPy (works with CPython 2.6+ and 3.2+ as well as PyPy)
110-
* gevent (works with CPython 2.6+)
111-
* wsgiref
112-
113-
Tornado already offers its own implementation.
114-
115-
Getting Started
116-
===============
117-
118-
Requirements
119-
------------
120-
121-
As a standalone client, ws4py only requires Python (2.6+ or 3.x).
122-
123-
* Tornado client requires Tornado 2.0.x (https://github.com/facebook/tornado)
124-
* CherryPy server requires CherryPy 3.2.2 (http://dowload.cherrypy.org/cherrypy/3.2.2/)
125-
* gevent server requires gevent gevent 0.13.6 and 1.0.0dev (http://pypi.python.org/pypi/gevent/0.13.6)
126-
* SL4A for Android support (http://code.google.com/p/android-scripting/)
127-
128-
Since not everyone will want all of them, ws4py will not attempt to install them automatically.
129-
130-
Installing
131-
----------
132-
133-
In order to install ws4py you can either grab the source code and run:
134-
135-
```
136-
$ python setup.py install
137-
```
138-
139-
Or use a package manager like pip and run:
140-
141-
```
142-
$ pip install ws4py
143-
```
144-
145-
or even:
146-
147-
```
148-
$ pip install git+git://github.com/Lawouach/WebSocket-for-Python.git
149-
```
150-
151-
Documentation
152-
-------------
153-
154-
Online documentation can be found at: https://ws4py.readthedocs.org/en/latest/
155-
156-
Continuous Build
157-
----------------
158-
159-
Travis is running continuous building against the master branch at:
160-
161-
https://travis-ci.org/#!/Lawouach/WebSocket-for-Python
162-
163-
Conformance
164-
-----------
165-
166-
ws4py tries hard to be as conformant as it can to the specification. In order to validate this conformance, each release is run against the Autobahn testsuite (http://autobahn.ws/) which provides an extensive converage of various aspects of the protocol.
167-
168-
You will require the Autobahn test suite:
169-
170-
```
171-
$ pip install autobahntestsuite
172-
```
173-
174-
In order to test the conformance of ws4py along other Python implementations, namely Autobahn 0.5+ and Tornado, run the followings:
175-
176-
```
177-
$ cd test
178-
$ python autobahn_test_servers.py --run-all
179-
```
180-
181-
Next, run the Autobahn test suite from the ws4py test directory:
182-
183-
```
184-
$ wstest -m fuzzingclient -s fuzzingclient.json
185-
```
186-
187-
Once the tests have finished, reports will be available from ```test/reports/servers```.
188-
189-
Online test reports can be found at: http://www.defuze.org/oss/ws4py/testreports/servers/
190-
191-
Browser Support
192-
---------------
193-
194-
ws4py has been tested using:
195-
196-
* Chromium 22
197-
* Firefox 16
198-
199-
Since Safari, Opera and IE do not yet support the protocol or the RFC's version, ws4py won't
200-
work with them. See http://caniuse.com/websockets for reference.
201-
202-
Bear in mind that time is a premium and maintaining obsolete and unsecure protocols is not
203-
one of ws4py's goals. It's therefore unlikely it will ever support them.
204-
205-
Examples
206-
--------
207-
208-
ws4py comes with a few examples:
209-
210-
* The ```echo_cherrypy_server``` example provides a simple Echo server. It requires CherryPy 3.2.2.
211-
Open a couple of tabs pointing at http://localhost:9000 and chat accross those tables.
212-
* The ```droid_sensor_cherrypy_server``` broadcasts sensor metrics to clients. Point your browser to http://localhost:9000
213-
Then run the ```droid_sensor``` module from your Android device using SL4A.
214-
A screenshot of what this renders to: http://www.defuze.org/oss/ws4py/screenshots/droidsensors.png
215-
You will find a lovely video of this demo in action at https://www.youtube.com/watch?v=baD-rShmZcM. Thanks to Mat Bettinson for this.
216-
217-
Credits
218-
-------
219-
220-
Many thanks to the pywebsocket and Tornado projects which have provided a good base to write ws4py.
221-
Thanks also to Jeff Lindsay (progrium) for the gevent server support.
222-
A well deserved thank you to Tobias Oberstein for his websocket test suite: https://github.com/oberstet/Autobahn
6+
Read the `documentation <https://ws4py.readthedocs.org/en/latest/>`_ for more information

docs/index.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ ws4py is a Python package implementing the WebSocket protocol as defined in `RFC
77

88
It provides client and server implementations alike that using different techniques like threads, micro-threads or event loops.
99

10-
Getting Started
11-
===============
10+
ws4py is released under a `BSD <https://github.com/Lawouach/WebSocket-for-Python/blob/master/LICENSE>`_ license.
11+
12+
Overview
13+
========
1214

1315
.. toctree::
1416
:maxdepth: 1
1517

1618
sources/requirements
1719
sources/install
20+
sources/conformance
21+
sources/browser
22+
sources/performance
23+
sources/credits
1824

1925

2026
Tutorial
@@ -27,6 +33,7 @@ Tutorial
2733
sources/clienttutorial
2834
sources/servertutorial
2935
sources/managertutorial
36+
sources/examples
3037

3138
Maintainer Guide
3239
================

docs/sources/browser.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.. _browser:
2+
3+
Browser Support
4+
===============
5+
6+
ws4py has been tested using:
7+
8+
- Chromium 22
9+
- Firefox 16
10+
11+
See http://caniuse.com/websockets to determine the current
12+
implementation's status of various browser vendors.
13+
14+
Bear in mind that time is a premium and maintaining obsolete and unsecure
15+
protocols is not one of ws4py's goals. It's therefore unlikely it will ever support older
16+
versions of the protocol.

docs/sources/conformance.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.. _conformance:
2+
3+
Conformance
4+
===========
5+
6+
7+
ws4py tries hard to be as conformant as it can to the specification.
8+
In order to validate this conformance, each release is run against the
9+
`Autobahn testsuite <http://autobahn.ws/>`_ which provides an extensive
10+
coverage of various aspects of the protocol.
11+
12+
Online test reports can be found at: http://www.defuze.org/oss/ws4py/testreports/servers/

docs/sources/credits.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. _credits:
2+
3+
Credits
4+
=======
5+
6+
Many thanks to the pywebsocket and Tornado projects which have provided a the starting point for ws4py.
7+
Thanks also to Jeff Lindsay (progrium) for the initial gevent server support.
8+
A well deserved thank you to Tobias Oberstein for `Autobahn <http://autobahn.ws/>`_ test suite.
9+
10+
Obviously thanks to all the various folks who have provided bug reports and fixes.

docs/sources/examples.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.. _examples:
2+
3+
Built-in Examples
4+
=================
5+
6+
Real-time chat
7+
--------------
8+
9+
The ``echo_cherrypy_server`` example provides a simple Echo server.
10+
It requires CherryPy 3.2.3. Open a couple of tabs pointing at http://localhost:9000
11+
and chat around.
12+
13+
Android sensors and HTML5
14+
-------------------------
15+
16+
The ``droid_sensor_cherrypy_server`` broadcasts sensor metrics to clients.
17+
Point your browser to http://localhost:9000
18+
Then run the ``droid_sensor`` module from your Android device using
19+
`SL4A <http://code.google.com/p/android-scripting/>`_.
20+
21+
A screenshot of what this renders to can be found `here <http://www.defuze.org/oss/ws4py/screenshots/droidsensors.png>`_.
22+
23+
You will find a lovely `video <https://www.youtube.com/watch?v=baD-rShmZcM>`_ of this demo in action
24+
on YouTube thanks to Mat Bettinson for this.

docs/sources/maintainer/design.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
Design
44
======
55

6+
Workflow
7+
--------
8+
69
ws4py's design is actually fairly simple and straigtforward. At a high level this is what is going on:
710

811
.. seqdiag::
@@ -37,4 +40,22 @@ which is passed on to the global ws4py :class:`ws4py.manager.WebSocketManager` i
3740
Most notably, the manager will poll for the socket's receive events so that, when bytes are available,
3841
the websocket object can read and process them.
3942

43+
Implementation
44+
--------------
45+
46+
ws4py data model is rather simple and follows the protocol itself:
47+
48+
a highlevel WebSocket class that determines actions to carry based on messages that are parsed.
49+
a Stream class that handles a single message at a time
50+
a Frame class that performs the low level protocol parsing of frames
51+
Each are inter-connected as russian dolls generators. The process heavily relies on the capacity to send to a generator. So everytime one of those layers requires something, it yields and then its holder sends it back whatever was required.
52+
53+
The Frame parser yields the number of bytes it needs at any time, the stream parser forwards it back to the WebSocket class which gets data from the underlying data provider it holds a reference to (a socket typically). The WebSocket class sends bytes as they are read from the socket down to the stream parser which forwards them to the frame parser.
54+
55+
Eventually a frame is parsed and handled by the stream parser which in turns yields a complete message made of all parsed frames.
56+
57+
The interesting aspect here is that the socket provider is totally abstracted from the protocol implementation which simply requires bytes as they come.
58+
59+
This means one could write a ws4py socket provider that doesn't read from the wire but from any other source.
4060

61+
It's also pretty fast and easy to read.

docs/sources/performance.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. _perf:
2+
3+
Perfomances
4+
===========
5+
6+
ws4py doesn't perform too bad but it's far from being the fastest WebSocket lib under heavy load.
7+
The reason is that it was first designed to implement the protocol with simplicity and clarity in mind.
8+
Future developments will look at performances.
9+
10+
.. note::
11+
12+
ws4py runs faster in some cases on PyPy than it does on CPython.
13+
14+
.. note::
15+
16+
The `wsaccel <https://github.com/methane/wsaccel>`_ package
17+
replaces some internal bottleneck with a Cython implementation.

docs/sources/requirements.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Tested environments:
1111
- Python 2.7+
1212
- Python 3.2+
1313
- PyPy 1.8+
14+
- Android 2.3 via `SL4A <http://code.google.com/p/android-scripting/>`_
1415

1516
.. note::
1617

0 commit comments

Comments
 (0)