Skip to content

Commit cdba0dc

Browse files
committed
Send image data
1 parent ee4c8e5 commit cdba0dc

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

examples/client/asyncio/latency_client.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import time
33
import socketio
44

5+
IMG_PATH='received.txt'
6+
57
loop = asyncio.get_event_loop()
68
sio = socketio.AsyncClient()
79
start_timer = None
@@ -20,16 +22,21 @@ async def connect():
2022

2123

2224
@sio.event
23-
async def pong_from_server():
25+
async def pong_from_server(data):
26+
print('Received pong from server.')
2427
global start_timer
25-
latency = time.time() - start_timer
26-
print('latency is {0:.2f} ms'.format(latency * 1000))
28+
# print(data)
29+
# latency = time.time() - start_timer
30+
# print('latency is {0:.2f} ms'.format(latency * 1000))
31+
image_data = data['image_data']
32+
with open(IMG_PATH, 'wb') as file:
33+
file.write(image_data)
2734
await sio.sleep(1)
2835
await send_ping()
2936

3037

3138
async def start_server():
32-
await sio.connect('http://localhost:5000')
39+
await sio.connect('http://localhost:8080')
3340
await sio.wait()
3441

3542

examples/client/asyncio/received.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

examples/server/aiohttp/latency.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from aiohttp import web
22

33
import socketio
4+
import base64
5+
6+
IMG_PATH = 'test.jpg'
47

58
sio = socketio.AsyncServer(async_mode='aiohttp', cors_allowed_origins='*')
69
app = web.Application()
@@ -11,10 +14,11 @@ async def index(request):
1114
with open('latency.html') as f:
1215
return web.Response(text=f.read(), content_type='text/html')
1316

14-
1517
@sio.event
1618
async def ping_from_client(sid):
17-
await sio.emit('pong_from_server', room=sid)
19+
with open(IMG_PATH, 'rb') as file:
20+
image_data = base64.b64encode(file.read())
21+
await sio.emit('pong_from_server', {'image_data': image_data}, room=sid)
1822

1923
@sio.event
2024
async def connect(sid, environment):

examples/server/aiohttp/test.jpg

2.48 MB
Loading

0 commit comments

Comments
 (0)