-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.py
More file actions
42 lines (30 loc) · 841 Bytes
/
Client.py
File metadata and controls
42 lines (30 loc) · 841 Bytes
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
import re
import socket
import time
import sys
import ssl
HOST = 'localhost'
PORT = 5004
context = ssl.create_default_context()
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
context.verify_mode = ssl.CERT_REQUIRED
context.check_hostname = True
# use the cacert.pem the check whether the certificate can be trusted
context.load_verify_locations("/cacert.pem")
#context = ssl.create_default_context()
conn = context.wrap_socket(socket.socket(socket.AF_INET),server_hostname="Jun Lu")
conn.connect(("localhost", PORT))
# send the command message
conn.sendall(b'CMD_short:0')
# receive data
received = 0
while True:
data = conn.recv(10000).decode()
if not data:
break
received += 1
print (data)
time.sleep(0.5)
# print the times of recv() invoked
print(str(received) + ' messages received!')
conn.close()