Skip to content

Commit 8337973

Browse files
readme file updates
1 parent 3556c3e commit 8337973

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

README.rst

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ Features
1818
Socket.IO specification.
1919
- Compatible with Python 2.7 and Python 3.3+.
2020
- Supports large number of clients even on modest hardware when used with an
21-
asynchronous server based on `eventlet <http://eventlet.net/>`_ or
22-
`gevent <http://gevent.org/>`_. For development and testing, any WSGI
23-
complaint multi-threaded server can be used.
21+
asynchronous server based on `asyncio <https://docs.python.org/3/library/asyncio.html>`_,
22+
`eventlet <http://eventlet.net/>`_ or `gevent <http://gevent.org/>`_. For
23+
development and testing, any WSGI complaint multi-threaded server can also be
24+
used.
2425
- Includes a WSGI middleware that integrates Socket.IO traffic with standard
2526
WSGI applications.
2627
- Broadcasting of messages to all connected clients, or to subsets of them
@@ -40,8 +41,44 @@ Features
4041
Example
4142
-------
4243

43-
The following application uses Flask to serve the HTML/Javascript to the
44-
client:
44+
The following eample application uses the `aiohttp <http://aiohttp.readthedocs.io/>`_
45+
framework for asyncio:
46+
47+
.. code:: python
48+
49+
from aiohttp import web
50+
import socketio
51+
52+
sio = socketio.AsyncServer()
53+
app = web.Application()
54+
sio.attach(app)
55+
56+
async def index(request):
57+
"""Serve the client-side application."""
58+
with open('index.html') as f:
59+
return web.Response(text=f.read(), content_type='text/html')
60+
61+
@sio.on('connect', namespace='/chat')
62+
def connect(sid, environ):
63+
print("connect ", sid)
64+
65+
@sio.on('chat message', namespace='/chat')
66+
async def message(sid, data):
67+
print("message ", data)
68+
await sio.emit('reply', room=sid)
69+
70+
@sio.on('disconnect', namespace='/chat')
71+
def disconnect(sid):
72+
print('disconnect ', sid)
73+
74+
app.router.add_static('/static', 'static')
75+
app.router.add_get('/', index)
76+
77+
if __name__ == '__main__':
78+
web.run_app(app)
79+
80+
And below is a similar example, using Flask to serve the client application.
81+
This example is compatible with Python 2.7 and Python 3.3+:
4582

4683
.. code:: python
4784
@@ -84,8 +121,5 @@ Resources
84121
- `Documentation`_
85122
- `PyPI`_
86123

87-
.. _Socket.IO: https://github.com/Automattic/socket.io
88-
.. _socket.io-client: https://github.com/Automattic/socket.io-client
89-
.. _Eventlet: http://eventlet.net/
90124
.. _Documentation: http://pythonhosted.org/python-socketio
91125
.. _PyPI: https://pypi.python.org/pypi/python-socketio

0 commit comments

Comments
 (0)