-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_client.py
64 lines (55 loc) · 1.9 KB
/
test_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import socket
import pickle
import select
from engine.settings import *
if __name__ == "__main__":
sk_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sk_server.connect((SERVER_IP, SERVER_PORT))
except Exception as error:
print(f"[WARNING] {error}")
exit(1)
# * MAIN LOOP * #
while True:
ready_sockets, _, _ = select.select([sk_server], [], [], CLIENT_TIMEOUT)
try:
if ready_sockets:
try:
data = pickle.loads(sk_server.recv(HEADER))
except Exception as error:
print(f"[GLOBAL WARNING] {error}")
continue
if isinstance(data, str) and data == "":
pass
elif isinstance(data, str) and data == "":
pass
'''
# 回应服务端
response = {
"commands": [
{
"animation": {
"aaa": 1,
"bbb": 2,
"ccc": 3
}
},
{
"attack": {
"fk": 666,
"st": 888,
"ah": 999
}
}
],
'id': -1
}
response = {"action": "commands", "value": response}
print(response)
'''
# sk_server.send(pickle.dumps(response))
except Exception as error:
print(f"[GLOBAL ERROR] {error}")
sk_server.send(pickle.dumps({'action': 'error', 'value': {'error': error}}))
# traceback.print_exc()
exit(0)