File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,35 @@ The example that follows shows a simple Python client:
6868 sio.connect(' http://localhost:5000' )
6969 sio.wait()
7070
71+ Below is a similar client, coded for ``asyncio `` (Python 3.5+ only):
72+
73+ .. code :: python
74+
75+ import asyncio
76+ import socketio
77+
78+ sio = socketio.AsyncClient()
79+
80+ @sio.event
81+ async def connect ():
82+ print (' connection established' )
83+
84+ @sio.event
85+ async def my_message (data ):
86+ print (' message received with ' , data)
87+ await sio.emit(' my response' , {' response' : ' my response' })
88+
89+ @sio.event
90+ async def disconnect ():
91+ print (' disconnected from server' )
92+
93+ async def main ():
94+ await sio.connect(' http://localhost:5000' )
95+ await sio.wait()
96+
97+ if __name__ == ' __main__' :
98+ asyncio.run(main())
99+
71100 Client Features
72101---------------
73102
@@ -137,7 +166,6 @@ Uvicorn web server:
137166 @sio.event
138167 async def chat_message (sid , data ):
139168 print (" message " , data)
140- await sio.emit(' reply' , room = sid)
141169
142170 @sio.event
143171 def disconnect (sid ):
You can’t perform that action at this time.
0 commit comments