Debian Codegraph @

example/tls/client.py

raw
1 #!/usr/bin/env python
2
3 import pathlib
4 import ssl
5
6 from websockets.sync.client import connect
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 def hello():
13 uri = "wss://localhost:8765"
14 with connect(uri, ssl=ssl_context) as websocket:
15 name = input("What's your name? ")
16
17 websocket.send(name)
18 print(f">>> {name}")
19
20 greeting = websocket.recv()
21 print(f"<<< {greeting}")
22
23 if __name__ == "__main__":
24 hello()