summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/tools/third_party/websockets/example/quickstart/client_secure.py
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/tools/third_party/websockets/example/quickstart/client_secure.py')
-rw-r--r--testing/web-platform/tests/tools/third_party/websockets/example/quickstart/client_secure.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/quickstart/client_secure.py b/testing/web-platform/tests/tools/third_party/websockets/example/quickstart/client_secure.py
new file mode 100644
index 0000000000..f4b39f2b83
--- /dev/null
+++ b/testing/web-platform/tests/tools/third_party/websockets/example/quickstart/client_secure.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+import asyncio
+import pathlib
+import ssl
+import websockets
+
+ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
+localhost_pem = pathlib.Path(__file__).with_name("localhost.pem")
+ssl_context.load_verify_locations(localhost_pem)
+
+async def hello():
+ uri = "wss://localhost:8765"
+ async with websockets.connect(uri, ssl=ssl_context) as websocket:
+ name = input("What's your name? ")
+
+ await websocket.send(name)
+ print(f">>> {name}")
+
+ greeting = await websocket.recv()
+ print(f"<<< {greeting}")
+
+if __name__ == "__main__":
+ asyncio.run(hello())