@@ -4,125 +4,14 @@ python-socketio
4
4
.. image :: https://travis-ci.org/miguelgrinberg/python-socketio.svg?branch=master
5
5
:target: https://travis-ci.org/miguelgrinberg/python-socketio
6
6
7
- Python implementation of the `Socket.IO <https://github.com/Automattic/socket.io >`_
8
- realtime server.
9
-
10
- Features
11
- --------
12
-
13
- - Fully compatible with the
14
- `Javascript <https://github.com/Automattic/socket.io-client >`_,
15
- `Swift <https://github.com/socketio/socket.io-client-swift >`_,
16
- `C++ <https://github.com/socketio/socket.io-client-cpp >`_ and
17
- `Java <https://github.com/socketio/socket.io-client-java >`_ official
18
- Socket.IO clients, plus any third party clients that comply with the
19
- Socket.IO specification.
20
- - Compatible with Python 2.7 and Python 3.3+.
21
- - Supports large number of clients even on modest hardware when used with an
22
- asynchronous server based on `asyncio <https://docs.python.org/3/library/asyncio.html >`_
23
- (`sanic <http://sanic.readthedocs.io/ >`_, `aiohttp <http://aiohttp.readthedocs.io/ >`_
24
- or `tornado <http://www.tornadoweb.org/ >`_),
25
- `eventlet <http://eventlet.net/ >`_ or `gevent <http://gevent.org/ >`_. For
26
- development and testing, any WSGI compliant multi-threaded server can also be
27
- used.
28
- - Includes a WSGI middleware that integrates Socket.IO traffic with standard
29
- WSGI applications.
30
- - Broadcasting of messages to all connected clients, or to subsets of them
31
- assigned to "rooms".
32
- - Optional support for multiple servers, connected through a messaging queue
33
- such as Redis or RabbitMQ.
34
- - Send messages to clients from external processes, such as Celery workers or
35
- auxiliary scripts.
36
- - Event-based architecture implemented with decorators that hides the details
37
- of the protocol.
38
- - Support for HTTP long-polling and WebSocket transports.
39
- - Support for XHR2 and XHR browsers.
40
- - Support for text and binary messages.
41
- - Support for gzip and deflate HTTP compression.
42
- - Configurable CORS responses, to avoid cross-origin problems with browsers.
43
-
44
- Example
45
- -------
46
-
47
- The following example application uses the `aiohttp <http://aiohttp.readthedocs.io/ >`_
48
- framework for asyncio:
49
-
50
- .. code :: python
51
-
52
- from aiohttp import web
53
- import socketio
54
-
55
- sio = socketio.AsyncServer()
56
- app = web.Application()
57
- sio.attach(app)
58
-
59
- async def index (request ):
60
- """ Serve the client-side application."""
61
- with open (' index.html' ) as f:
62
- return web.Response(text = f.read(), content_type = ' text/html' )
63
-
64
- @sio.on (' connect' , namespace = ' /chat' )
65
- def connect (sid , environ ):
66
- print (" connect " , sid)
67
-
68
- @sio.on (' chat message' , namespace = ' /chat' )
69
- async def message (sid , data ):
70
- print (" message " , data)
71
- await sio.emit(' reply' , room = sid)
72
-
73
- @sio.on (' disconnect' , namespace = ' /chat' )
74
- def disconnect (sid ):
75
- print (' disconnect ' , sid)
76
-
77
- app.router.add_static(' /static' , ' static' )
78
- app.router.add_get(' /' , index)
79
-
80
- if __name__ == ' __main__' :
81
- web.run_app(app)
82
-
83
- And below is a similar example, using Flask to serve the client application.
84
- This example is compatible with Python 2.7 and Python 3.3+:
85
-
86
- .. code :: python
87
-
88
- import socketio
89
- import eventlet
90
- import eventlet.wsgi
91
- from flask import Flask, render_template
92
-
93
- sio = socketio.Server()
94
- app = Flask(__name__ )
95
-
96
- @app.route (' /' )
97
- def index ():
98
- """ Serve the client-side application."""
99
- return render_template(' index.html' )
100
-
101
- @sio.on (' connect' , namespace = ' /chat' )
102
- def connect (sid , environ ):
103
- print (" connect " , sid)
104
-
105
- @sio.on (' chat message' , namespace = ' /chat' )
106
- def message (sid , data ):
107
- print (" message " , data)
108
- sio.emit(' reply' , room = sid)
109
-
110
- @sio.on (' disconnect' , namespace = ' /chat' )
111
- def disconnect (sid ):
112
- print (' disconnect ' , sid)
113
-
114
- if __name__ == ' __main__' :
115
- # wrap Flask application with engineio's middleware
116
- app = socketio.Middleware(sio, app)
117
-
118
- # deploy as an eventlet WSGI server
119
- eventlet.wsgi.server(eventlet.listen((' ' , 8000 )), app)
7
+ Python implementation of the `Socket.IO `_ realtime client and server.
120
8
121
9
Resources
122
10
---------
123
11
124
12
- `Documentation `_
125
13
- `PyPI `_
126
14
15
+ .. _Socket.IO : https://github.com/socketio/socket.io
127
16
.. _Documentation : http://python-socketio.readthedocs.io/en/latest/
128
17
.. _PyPI : https://pypi.python.org/pypi/python-socketio
0 commit comments