You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
580 B

import time
import socketio
sio = socketio.Client(logger=True, engineio_logger=True)
start_timer = None
def send_ping():
global start_timer
start_timer = time.time()
sio.emit('ping_from_client')
@sio.event
def connect():
print('connected to server')
send_ping()
@sio.event
def pong_from_server():
global start_timer
latency = time.time() - start_timer
print(f'latency is {latency * 1000:.2f} ms')
sio.sleep(1)
if sio.connected:
send_ping()
if __name__ == '__main__':
sio.connect('http://localhost:5000')
sio.wait()