Skip to content

Commit 4822d81

Browse files
reorganization of examples, plus some new ones for the client
1 parent fc5fbcf commit 4822d81

Some content is hidden

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

62 files changed

+170
-24
lines changed

examples/README.rst

Lines changed: 3 additions & 22 deletions

examples/client/README.rst

Lines changed: 15 additions & 0 deletions

examples/client/asyncio/README.rst

Lines changed: 24 additions & 0 deletions
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import asyncio
2+
import time
3+
import socketio
4+
5+
loop = asyncio.get_event_loop()
6+
sio = socketio.AsyncClient()
7+
start_timer = None
8+
9+
10+
async def send_ping():
11+
global start_timer
12+
start_timer = time.time()
13+
await sio.emit('ping_from_client')
14+
15+
16+
@sio.on('connect')
17+
async def on_connect():
18+
print('connected to server')
19+
await send_ping()
20+
21+
22+
@sio.on('pong_from_server')
23+
async def on_pong(data):
24+
global start_timer
25+
latency = time.time() - start_timer
26+
print('latency is {0:.2f} ms'.format(latency * 1000))
27+
await sio.sleep(1)
28+
await send_ping()
29+
30+
31+
async def start_server():
32+
await sio.connect('http://localhost:5000')
33+
await sio.wait()
34+
35+
36+
if __name__ == '__main__':
37+
loop.run_until_complete(start_server())

examples/client/threads/README.rst

Lines changed: 24 additions & 0 deletions
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import time
2+
import socketio
3+
4+
sio = socketio.Client()
5+
start_timer = None
6+
7+
8+
def send_ping():
9+
global start_timer
10+
start_timer = time.time()
11+
sio.emit('ping_from_client')
12+
13+
14+
@sio.on('connect')
15+
def on_connect():
16+
print('connected to server')
17+
send_ping()
18+
19+
20+
@sio.on('pong_from_server')
21+
def on_pong(data):
22+
global start_timer
23+
latency = time.time() - start_timer
24+
print('latency is {0:.2f} ms'.format(latency * 1000))
25+
sio.sleep(1)
26+
send_ping()
27+
28+
29+
if __name__ == '__main__':
30+
sio.connect('http://localhost:5000')
31+
sio.wait()

examples/server/README.rst

Lines changed: 30 additions & 0 deletions

0 commit comments

Comments
 (0)