summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/tools/third_party/websockets/example/legacy
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/tools/third_party/websockets/example/legacy')
-rw-r--r--testing/web-platform/tests/tools/third_party/websockets/example/legacy/basic_auth_client.py14
-rw-r--r--testing/web-platform/tests/tools/third_party/websockets/example/legacy/basic_auth_server.py21
-rw-r--r--testing/web-platform/tests/tools/third_party/websockets/example/legacy/unix_client.py19
-rw-r--r--testing/web-platform/tests/tools/third_party/websockets/example/legacy/unix_server.py23
4 files changed, 77 insertions, 0 deletions
diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/legacy/basic_auth_client.py b/testing/web-platform/tests/tools/third_party/websockets/example/legacy/basic_auth_client.py
new file mode 100644
index 0000000000..164732152f
--- /dev/null
+++ b/testing/web-platform/tests/tools/third_party/websockets/example/legacy/basic_auth_client.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+
+# WS client example with HTTP Basic Authentication
+
+import asyncio
+import websockets
+
+async def hello():
+ uri = "ws://mary:p@ssw0rd@localhost:8765"
+ async with websockets.connect(uri) as websocket:
+ greeting = await websocket.recv()
+ print(greeting)
+
+asyncio.run(hello())
diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/legacy/basic_auth_server.py b/testing/web-platform/tests/tools/third_party/websockets/example/legacy/basic_auth_server.py
new file mode 100644
index 0000000000..d2efeb7e53
--- /dev/null
+++ b/testing/web-platform/tests/tools/third_party/websockets/example/legacy/basic_auth_server.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+
+# Server example with HTTP Basic Authentication over TLS
+
+import asyncio
+import websockets
+
+async def hello(websocket):
+ greeting = f"Hello {websocket.username}!"
+ await websocket.send(greeting)
+
+async def main():
+ async with websockets.serve(
+ hello, "localhost", 8765,
+ create_protocol=websockets.basic_auth_protocol_factory(
+ realm="example", credentials=("mary", "p@ssw0rd")
+ ),
+ ):
+ await asyncio.Future() # run forever
+
+asyncio.run(main())
diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/legacy/unix_client.py b/testing/web-platform/tests/tools/third_party/websockets/example/legacy/unix_client.py
new file mode 100644
index 0000000000..9261567303
--- /dev/null
+++ b/testing/web-platform/tests/tools/third_party/websockets/example/legacy/unix_client.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+
+# WS client example connecting to a Unix socket
+
+import asyncio
+import os.path
+import websockets
+
+async def hello():
+ socket_path = os.path.join(os.path.dirname(__file__), "socket")
+ async with websockets.unix_connect(socket_path) as websocket:
+ name = input("What's your name? ")
+ await websocket.send(name)
+ print(f">>> {name}")
+
+ greeting = await websocket.recv()
+ print(f"<<< {greeting}")
+
+asyncio.run(hello())
diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/legacy/unix_server.py b/testing/web-platform/tests/tools/third_party/websockets/example/legacy/unix_server.py
new file mode 100644
index 0000000000..335039c351
--- /dev/null
+++ b/testing/web-platform/tests/tools/third_party/websockets/example/legacy/unix_server.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+# WS server example listening on a Unix socket
+
+import asyncio
+import os.path
+import websockets
+
+async def hello(websocket):
+ name = await websocket.recv()
+ print(f"<<< {name}")
+
+ greeting = f"Hello {name}!"
+
+ await websocket.send(greeting)
+ print(f">>> {greeting}")
+
+async def main():
+ socket_path = os.path.join(os.path.dirname(__file__), "socket")
+ async with websockets.unix_serve(hello, socket_path):
+ await asyncio.Future() # run forever
+
+asyncio.run(main())