Skip to content

Commit c91244a

Browse files
Documentation updates
1 parent cfda1b2 commit c91244a

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ socketio = SocketIO(app)
2727
def index():
2828
return render_template('index.html')
2929

30-
@socketio.on('my event')
31-
def test_message(message):
30+
@socketio.event
31+
def my_event(message):
3232
emit('my response', {'data': 'got it!'})
3333

3434
if __name__ == '__main__':

docs/index.rst

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,34 @@ to coordinate operations such as broadcasting. The supported queues are
5454
other message queues supported by the
5555
`Kombu <http://kombu.readthedocs.org/en/latest/>`_ package.
5656

57-
On the client-side, the official Socket.IO Javascript client library versions
58-
1.x or 2.x can be used to establish a connection to the server (work to support
59-
the 3.x release is in progress). There are also official clients written in
60-
Swift, Java and C++. Unofficial clients may also work, as long as they
61-
implement the
57+
On the client-side, the official Socket.IO Javascript client library can be
58+
used to establish a connection to the server. There are also official clients
59+
written in Swift, Java and C++. Unofficial clients may also work, as long as
60+
they implement the
6261
`Socket.IO protocol <https://github.com/socketio/socket.io-protocol>`_.
62+
The `python-socketio <https://github.com/miguelgrinberg/python-socketio>`_
63+
package includes a Python client.
64+
65+
Version compatibility
66+
---------------------
67+
68+
The Socket.IO protocol has been through a number of revisions, and some of these
69+
introduced backward incompatible changes, which means that the client and the
70+
server must use compatible versions for everything to work.
71+
72+
The version compatibility chart below maps versions of this package to versions
73+
of the JavaScript reference implementation and the versions of the Socket.IO and
74+
Engine.IO protocols.
75+
76+
+------------------------------+-----------------------------+-----------------------------+------------------------+-------------------------+
77+
| JavaScript Socket.IO version | Socket.IO protocol revision | Engine.IO protocol revision | Flask-SocketIO version | python-socketio version |
78+
+==============================+=============================+=============================+========================+=========================+
79+
| 0.9.x | 1, 2 | 1, 2 | Not supported | Not supported |
80+
+------------------------------+-----------------------------+-----------------------------+------------------------+-------------------------+
81+
| 1.x and 2.x | 3, 4 | 3 | 4.x | 4.x |
82+
+------------------------------+-----------------------------+-----------------------------+------------------------+-------------------------+
83+
| 3.x | 5 | 4 | 5.x | 5.x |
84+
+------------------------------+-----------------------------+-----------------------------+------------------------+-------------------------+
6385

6486
Initialization
6587
--------------
@@ -118,8 +140,8 @@ The following example creates a server-side event handler for an unnamed
118140
event::
119141

120142
@socketio.on('message')
121-
def handle_message(message):
122-
print('received message: ' + message)
143+
def handle_message(data):
144+
print('received message: ' + data)
123145

124146
The above example uses string messages. Another type of unnamed events use
125147
JSON data::
@@ -137,10 +159,17 @@ these events can be string, bytes, int, or JSON::
137159

138160
Custom named events can also support multiple arguments::
139161

140-
@socketio.on('my event')
162+
@socketio.on('my_event')
141163
def handle_my_custom_event(arg1, arg2, arg3):
142164
print('received args: ' + arg1 + arg2 + arg3)
143165

166+
When the name of the event is a valid Python identifier that does not collide
167+
with other defined symbols, the ``@socketio.event`` provides a more compact
168+
syntax that takes the event name from the decorated function::
169+
170+
@socketio.event
171+
def my_custom_event(arg1, arg2, arg3):
172+
print('received args: ' + arg1 + arg2 + arg3)
144173

145174
Named events are the most flexible, as they eliminate the need to include
146175
additional metadata to describe the message type. The names ``message``,

0 commit comments

Comments
 (0)