20 lines
473 B
Python
Executable File
20 lines
473 B
Python
Executable File
#!/usr/bin/env python
|
|
|
|
# WS server that sends messages at random intervals
|
|
|
|
import asyncio
|
|
import datetime
|
|
import random
|
|
import websockets
|
|
|
|
async def time(websocket, path):
|
|
while True:
|
|
now = datetime.datetime.utcnow().isoformat() + "Z"
|
|
await websocket.send('moche')
|
|
await asyncio.sleep(2)
|
|
|
|
start_server = websockets.serve(time, "127.0.0.1", 5678)
|
|
|
|
asyncio.get_event_loop().run_until_complete(start_server)
|
|
asyncio.get_event_loop().run_forever()
|