-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_server.py
48 lines (34 loc) · 873 Bytes
/
test_server.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
39
40
41
42
43
44
45
46
47
48
import socket
import ssl
HOST = "::1"
PORT = 1337
IPV6 = 1
SSL = 0
if __name__ == "__main__":
if IPV6:
server = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
else:
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if SSL:
server = ssl.wrap_socket(
server,
server_side=True,
keyfile="server-key.pem",
certfile="./server-cert.pem",
do_handshake_on_connect=True,
)
server.bind((HOST, PORT))
print(f'IPv6: {IPV6}, SSL: {SSL}')
print(f'Listening on {HOST} {PORT}')
server.listen(0)
while True:
#ssl.SSLContext.num_tickets = 0
connection, client_address = server.accept()
while True:
#ssl.SSLContext.num_tickets = 0
data = connection.recv(1024)
if not data:
break
print(f"Received: {data.decode('utf-8')}")
connection.sendall(b'ok')