Skip to content

Commit

Permalink
reorganized examples
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Feb 6, 2017
1 parent cbeb025 commit 824cdd5
Show file tree
Hide file tree
Showing 19 changed files with 4,370 additions and 51 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
example/static/engine.io.js linguist-vendored
example/wsgi/static/engine.io.js linguist-vendored
example/aiohttp/static/engine.io.js linguist-vendored
50 changes: 8 additions & 42 deletions examples/README.rst
Original file line number Diff line number Diff line change
@@ -1,49 +1,15 @@
Engine.IO Examples
==================

This directory contains example Engine.IO applications.
This directory contains several example Engine.IO applications, organized by
directory:

simple.py
---------
wsgi
----

A basic application in which the client sends messages to the server and the
server responds.
Examples that are compatible with the WSGI protocol and frameworks.

latency.py
----------
aiohttp
-------

A port of the latency application included in the official Engine.IO
Javascript server. In this application the client sends *ping* messages to
the server, which are responded by the server with a *pong*. The client
measures the time it takes for each of these exchanges and plots these in real
time to the page.

This is an ideal application to measure the performance of the different
asynchronous modes supported by the Engine.IO server.

Running the Examples
--------------------

To run these examples using the default ``'threading'`` mode, create a virtual
environment, install the requirements and then run::

$ python simple.py

or::

$ python latency.py

Near the top of the ``simple.py`` and ``latency.py`` source files there is a
``async_mode`` variable that can be edited to swich to the other asynchornous
modes. Accepted values for ``async_mode`` are ``'threading'``, ``'eventlet'``
and ``'gevent'``.

Note 1: when using the ``'eventlet'`` mode, the eventlet package must be
installed in the virtual environment::

$ pip install eventlet

Note 2: when using the ``'gevent'`` mode, the gevent and gevent-websocket
packages must be installed in the virtual environment::

$ pip install gevent gevent-websocket
Examples that are compatible with the aiohttp framework for asyncio.
39 changes: 39 additions & 0 deletions examples/aiohttp/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Engine.IO Examples
==================

This directory contains example Engine.IO applications that are compatible
with asyncio and the aiohttp framework. These applications require Python 3.5
or later.

simple.py
---------

A basic application in which the client sends messages to the server and the
server responds.

latency.py
----------

A port of the latency application included in the official Engine.IO
Javascript server. In this application the client sends *ping* messages to
the server, which are responded by the server with a *pong*. The client
measures the time it takes for each of these exchanges and plots these in real
time to the page.

This is an ideal application to measure the performance of the different
asynchronous modes supported by the Engine.IO server.

Running the Examples
--------------------

To run these examples, create a virtual environment, install the requirements
and then run::

$ python simple.py

or::

$ python latency.py

You can then access the application from your web browser at
``http://localhost:8080``.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


async def index(request):
with open('templates/latency_aiohttp.html') as f:
with open('latency.html') as f:
return web.Response(text=f.read(), content_type='text/html')


Expand Down
7 changes: 7 additions & 0 deletions examples/aiohttp/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
aiohttp==1.2.0
async-timeout==1.1.0
chardet==2.3.0
multidict==2.1.4
python-engineio
six==1.10.0
yarl==0.8.1
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/simple_aiohttp.py → examples/aiohttp/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


async def index(request):
with open('templates/simple_aiohttp.html') as f:
with open('simple.html') as f:
return web.Response(text=f.read(), content_type='text/html')


Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions examples/requirements.txt

This file was deleted.

55 changes: 55 additions & 0 deletions examples/wsgi/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Engine.IO WSGI Examples
=======================

This directory contains example Engine.IO applications that work together with
WSGI frameworks. These examples all use Flask to serve the client application
to the web browser, but they should be easily adapted to use other WSGI
compliant frameworks.

simple.py
---------

A basic application in which the client sends messages to the server and the
server responds.

latency.py
----------

A port of the latency application included in the official Engine.IO
Javascript server. In this application the client sends *ping* messages to
the server, which are responded by the server with a *pong*. The client
measures the time it takes for each of these exchanges and plots these in real
time to the page.

This is an ideal application to measure the performance of the different
asynchronous modes supported by the Engine.IO server.

Running the Examples
--------------------

To run these examples using the default ``'threading'`` mode, create a virtual
environment, install the requirements and then run::

$ python simple.py

or::

$ python latency.py

You can then access the application from your web browser at
``http://localhost:5000``.

Near the top of the ``simple.py`` and ``latency.py`` source files there is a
``async_mode`` variable that can be edited to swich to the other asynchornous
modes that perform much better than the threading mode. Accepted values for
``async_mode`` are ``'threading'``, ``'eventlet'`` and ``'gevent'``.

Note 1: when using the ``'eventlet'`` mode, the eventlet package must be
installed in the virtual environment::

$ pip install eventlet

Note 2: when using the ``'gevent'`` mode, the gevent and gevent-websocket
packages must be installed in the virtual environment::

$ pip install gevent gevent-websocket
File renamed without changes.
8 changes: 8 additions & 0 deletions examples/wsgi/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
click==6.7
Flask==0.12
itsdangerous==0.24
Jinja2==2.9.5
MarkupSafe==0.23
python-engineio
six==1.10.0
Werkzeug==0.11.15
File renamed without changes.
Loading

0 comments on commit 824cdd5

Please sign in to comment.