-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.1 Client.py
38 lines (30 loc) · 1.12 KB
/
3.1 Client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import socket
import ssl
SERVER_HOST = 'localhost'
SERVER_PORT = 12345
def main():
try:
# Create a TCP/IP socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Wrap socket with SSL/TLS encryption
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
ssl_socket = context.wrap_socket(client_socket, server_hostname=SERVER_HOST)
try:
# Connect to the server
ssl_socket.connect((SERVER_HOST, SERVER_PORT))
# Send message to server
message = "Client authentication data"
ssl_socket.send(message.encode())
# Receive response from server
response = ssl_socket.recv(1024)
print(f"Received: {response.decode()}")
except Exception as e:
print(f"Error communicating with the server: {e}")
finally:
ssl_socket.close()
except Exception as e:
print(f"Error setting up client: {e}")
if __name__ == "__main__":
main()