I successfully created a python 3.5 websocket server with the following code, but I'm now struggling to close the connection after n missed pings. How is this possible?
import asyncio
import websockets
import threading
def keepalive(conn):
last_pong = time.time()
def wrapper():
pong = conn.ping()
print('ping sent')
t = threading.Timer(10, wrapper)
t.start()
wrapper()
async def handler(conn, path):
await conn.send('hello')
keepalive(conn)
while True:
data = await conn.recv()
print('data: ', data)
start_server = websockets.serve(handler, 'localhost', 5000)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
I successfully created a python 3.5 websocket server with the following code, but I'm now struggling to close the connection after n missed pings. How is this possible?