-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_gameplay_client.py
More file actions
53 lines (45 loc) · 1.25 KB
/
test_gameplay_client.py
File metadata and controls
53 lines (45 loc) · 1.25 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
import socket
import select
import time
import struct
import json
# SETUP COMMAND RECEIVING SERVER
HOST = "192.168.0.248"
PORT = 65432
isConnected = False
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
isConnected = True
except OSError:
try:
s.sendall(b'Test')
isConnected = True
except OSError:
print("Something is wrong")
isConnected = False
pass
s.setblocking(0)
def main():
requested = False
try:
while isConnected:
# state = list(range(48))
state = [
0, 0, 0, 0.2, 0.4, 0, 0, 0, 0, 0.75, -1.8, 0, 0.75, -1.8, 0,
0.75, -1.8, 0, 0.75, -1.8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
if not requested:
s.sendall(struct.pack("!48f", *state))
requested = True
ready = select.select([s], [], [], 0.01)[0]
if ready:
data = s.recv(1024)
data = data.decode("utf-8")
print(json.loads(data)["g_x"])
requested = False
except KeyboardInterrupt:
print("done")
if __name__ == "__main__":
main()