summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/tools/third_party/websockets/example/quickstart/show_time_2.py
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/tools/third_party/websockets/example/quickstart/show_time_2.py')
-rw-r--r--testing/web-platform/tests/tools/third_party/websockets/example/quickstart/show_time_2.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/quickstart/show_time_2.py b/testing/web-platform/tests/tools/third_party/websockets/example/quickstart/show_time_2.py
new file mode 100644
index 0000000000..08e87f5931
--- /dev/null
+++ b/testing/web-platform/tests/tools/third_party/websockets/example/quickstart/show_time_2.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+import asyncio
+import datetime
+import random
+import websockets
+
+CONNECTIONS = set()
+
+async def register(websocket):
+ CONNECTIONS.add(websocket)
+ try:
+ await websocket.wait_closed()
+ finally:
+ CONNECTIONS.remove(websocket)
+
+async def show_time():
+ while True:
+ message = datetime.datetime.utcnow().isoformat() + "Z"
+ websockets.broadcast(CONNECTIONS, message)
+ await asyncio.sleep(random.random() * 2 + 1)
+
+async def main():
+ async with websockets.serve(register, "localhost", 5678):
+ await show_time()
+
+if __name__ == "__main__":
+ asyncio.run(main())