Skip to content

Commit cc9b3e9

Browse files
v5 protocol: updated all examples
1 parent 0ecfbf5 commit cc9b3e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+468
-29
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import asyncio
2+
import socketio
3+
4+
sio = socketio.AsyncClient()
5+
6+
7+
@sio.event
8+
async def connect():
9+
print('connected to server')
10+
11+
12+
@sio.event
13+
async def disconnect():
14+
print('disconnected from server')
15+
16+
17+
@sio.event
18+
def hello(a, b, c):
19+
print(a, b, c)
20+
21+
22+
async def start_server():
23+
await sio.connect('http://localhost:5000')
24+
await sio.wait()
25+
26+
27+
if __name__ == '__main__':
28+
asyncio.run(start_server())
File renamed without changes.
File renamed without changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import socketio
2+
3+
sio = socketio.Client()
4+
5+
6+
@sio.event
7+
def connect():
8+
print('connected to server')
9+
10+
11+
@sio.event
12+
def disconnect():
13+
print('disconnected from server')
14+
15+
16+
@sio.event
17+
def hello(a, b, c):
18+
print(a, b, c)
19+
20+
21+
if __name__ == '__main__':
22+
sio.connect('http://localhost:5000')
23+
sio.wait()

examples/server/aiohttp/README.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,27 @@ time to the page.
2323
This is an ideal application to measure the performance of the different
2424
asynchronous modes supported by the Socket.IO server.
2525

26+
fiddle.py
27+
---------
28+
29+
This is a very simple application based on a JavaScript example of the same
30+
name.
31+
2632
Running the Examples
2733
--------------------
2834

2935
To run these examples, create a virtual environment, install the requirements
30-
and then run::
36+
and then run one of the following::
3137

3238
$ python app.py
3339

34-
or::
40+
::
3541

3642
$ python latency.py
3743

44+
::
45+
46+
$ python fiddle.py
47+
3848
You can then access the application from your web browser at
3949
``http://localhost:8080``.

examples/server/aiohttp/app.html

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<title>python-socketio test</title>
55
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.4.min.js"></script>
6-
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.slim.js"></script>
6+
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
77
<script type="text/javascript" charset="utf-8">
88
$(document).ready(function(){
99
var socket = io.connect();

examples/server/aiohttp/app.py

100755100644
File mode changed.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Socket.IO Fiddle</title>
6+
</head>
7+
<body>
8+
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
9+
<script src="/static/fiddle.js"></script>
10+
</body>
11+
</html>

examples/server/aiohttp/fiddle.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from aiohttp import web
2+
3+
import socketio
4+
5+
sio = socketio.AsyncServer(async_mode='aiohttp')
6+
app = web.Application()
7+
sio.attach(app)
8+
9+
10+
async def index(request):
11+
with open('fiddle.html') as f:
12+
return web.Response(text=f.read(), content_type='text/html')
13+
14+
15+
@sio.event
16+
async def connect(sid, environ):
17+
print('connected', sid)
18+
await sio.emit('hello', (1, 2, {'hello': 'you'}), to=sid)
19+
20+
21+
@sio.event
22+
def disconnect(sid):
23+
print('disconnected', sid)
24+
25+
26+
app.router.add_static('/static', 'static')
27+
app.router.add_get('/', index)
28+
29+
30+
if __name__ == '__main__':
31+
web.run_app(app)

examples/server/aiohttp/latency.html

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h2 id="transport">(connecting)</h2>
1111

1212
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
1313
<script src="//cdnjs.cloudflare.com/ajax/libs/smoothie/1.27.0/smoothie.js"></script>
14-
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.slim.js"></script>
14+
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.min.js"></script>
1515
<script>
1616
// socket
1717
var socket = io.connect();

0 commit comments

Comments
 (0)