Debian Codegraph @

testing/web-platform/tests/tools/third_party/websockets/example/quickstart/client_secure.py

raw
1 #!/usr/bin/env python
2
3 import asyncio
4 import pathlib
5 import ssl
6 import websockets
7
8 ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
9 localhost_pem = pathlib.Path(__file__).with_name("localhost.pem")
10 ssl_context.load_verify_locations(localhost_pem)
11
12 async def hello():
13 uri = "wss://localhost:8765"
14 async with websockets.connect(uri, ssl=ssl_context) as websocket:
15 name = input("What's your name? ")
16
17 await websocket.send(name)
18 print(f">>> {name}")
19
20 greeting = await websocket.recv()
21 print(f"<<< {greeting}")
22
23 if __name__ == "__main__":
24 asyncio.run(hello())