diff options
Diffstat (limited to 'testing/web-platform/tests/tools/third_party/websockets/example/quickstart/show_time.py')
-rw-r--r-- | testing/web-platform/tests/tools/third_party/websockets/example/quickstart/show_time.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/quickstart/show_time.py b/testing/web-platform/tests/tools/third_party/websockets/example/quickstart/show_time.py new file mode 100644 index 0000000000..a83078e8a9 --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/quickstart/show_time.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python + +import asyncio +import datetime +import random +import websockets + +async def show_time(websocket): + while True: + message = datetime.datetime.utcnow().isoformat() + "Z" + await websocket.send(message) + await asyncio.sleep(random.random() * 2 + 1) + +async def main(): + async with websockets.serve(show_time, "localhost", 5678): + await asyncio.Future() # run forever + +if __name__ == "__main__": + asyncio.run(main()) |