Skip to content

Commit b59cefc

Browse files
Added docs on websocket support with gevent
1 parent 9cee038 commit b59cefc

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

docs/index.rst

+23-5
Original file line numberDiff line numberDiff line change
@@ -248,29 +248,44 @@ Gevent
248248
~~~~~~
249249

250250
`Gevent <http://gevent.org>`_ is another asynchronous framework based on
251-
coroutines, very similar to eventlet. Only the long-polling transport is
252-
currently available when using gevent.
251+
coroutines, very similar to eventlet. An Socket.IO server deployed with
252+
gevent has access to the long-polling transport. If project
253+
`gevent-websocket <https://bitbucket.org/Jeffrey/gevent-websocket/>`_ is
254+
installed, the WebSocket transport is also available.
253255

254256
Instances of class ``socketio.Server`` will automatically use gevent for
255257
asynchronous operations if the library is installed and eventlet is not
256258
installed. To request gevent to be selected explicitly, the ``async_mode``
257259
option can be given in the constructor::
258260

259-
eio = socketio.Server(async_mode='gevent')
261+
sio = socketio.Server(async_mode='gevent')
260262

261263
A server configured for gevent is deployed as a regular WSGI application,
262264
using the provided ``socketio.Middleware``::
263265

264-
app = socketio.Middleware(eio)
266+
app = socketio.Middleware(sio)
265267
from gevent import pywsgi
266268
pywsgi.WSGIServer(('', 8000), app).serve_forever()
267269

268-
An alternative to running the eventlet WSGI server as above is to use
270+
If the WebSocket transport is installed, then the server must be started as
271+
follows::
272+
273+
from gevent import pywsgi
274+
from geventwebsocket.handler import WebSocketHandler
275+
app = socketio.Middleware(sio)
276+
pywsgi.WSGIServer(('', 8000), app,
277+
handler_class=WebSocketHandler).serve_forever()
278+
279+
An alternative to running the gevent WSGI server as above is to use
269280
`gunicorn <gunicorn.org>`_, a fully featured pure Python web server. The
270281
command to launch the application under gunicorn is shown below::
271282

272283
$ gunicorn -k gevent -w 1 module:app
273284

285+
Or to include WebSocket::
286+
287+
$ gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 module: app
288+
274289
Same as with eventlet, due to limitations in its load balancing algorithm,
275290
gunicorn can only be used with one worker process, so the ``-w 1`` option is
276291
required. Note that a single eventlet worker can handle a large number of
@@ -316,6 +331,9 @@ can handle multiple concurrent requests using threads, since a client can have
316331
up to two outstanding requests at any given time. The Werkzeug server is
317332
single-threaded by default, so the ``threaded=True`` option is required.
318333

334+
Note that servers that use worker processes instead of threads, such as
335+
gunicorn, do not support a Socket.IO server configured in threading mode.
336+
319337
Multi-process deployments
320338
~~~~~~~~~~~~~~~~~~~~~~~~~
321339

setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
platforms='any',
2626
install_requires=[
2727
'six>=1.9.0',
28-
'eventlet>=0.17.4',
29-
'python-engineio>=0.5.0'
28+
'python-engineio>=0.6.0'
3029
],
3130
tests_require=[
3231
'mock',

0 commit comments

Comments
 (0)