-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
54 lines (36 loc) · 1.47 KB
/
client.py
File metadata and controls
54 lines (36 loc) · 1.47 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import socket
import ssl
from helper_functions import receiveBytes, sendBytes
SERVER_SOCKET_HOST = "192.168.0.104"
SERVER_SOCKET_PORT = 4449
USE_TLS = True
print("Starting client...")
clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
chosenSocket: socket.socket = clientSocket
if USE_TLS:
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode=ssl.CERT_NONE
# context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
# context.load_cert_chain(certfile="./client-security/cert.pem", keyfile="./client-security/key.pem")
# context.load_verify_locations('./server-security/cert.pem')
chosenSocket = context.wrap_socket(clientSocket, server_hostname=SERVER_SOCKET_HOST)
try:
print(
f"Connecting to server {SERVER_SOCKET_HOST} on port {SERVER_SOCKET_PORT}...")
chosenSocket.connect((SERVER_SOCKET_HOST, SERVER_SOCKET_PORT))
except Exception as e:
print("Error while trying to connect to remote socket.")
raise e
while True:
message = 'Lorem ipsum dolor sit amet.'
print("Sending message data to remote socket...")
try:
sendBytes(chosenSocket, bytes(message, "utf-8"))
received = receiveBytes(chosenSocket)
print(received.decode('utf-8'))
except Exception as e:
print("Failed sending message data to remote socket!")
raise e
# clientSocket.close()
input('Press enter')