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

25 lines
642 B
Python

#!/usr/bin/env python
# WS server that sends messages every second
import asyncio
import datetime
import random
import websockets
async def time(websocket, path):
while True:
# now = datetime.datetime.utcnow().isoformat() + "Z"
# myinput = open('mytxtfile.txt')
# txt = myinput.read()
# myinput.close()
with open('mytxtfile.txt') as myinput:
txt = myinput.read()
await websocket.send(txt)
await asyncio.sleep(1)
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()