-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_server.py
executable file
·37 lines (32 loc) · 1.46 KB
/
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
import socket
HOST = '127.0.0.1' # Standard loopback interface address (localhost)
PORT = 6350 # Port to listen on (non-privileged ports are > 1023)
valve = '00'
dry = '00'
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
while True:
conn, addr = s.accept()
with conn:
print('Connected by', addr)
while True:
data = conn.recv(1024)
if not data:
break
print(len(bytes.hex(data)))
if len(bytes.hex(data)) == 16:
data = bytes.fromhex(f'02544152005c4900054e333232304d001136303a43353a41383a37353a35313a333541000100530007{valve}0000{dry}0003017300004c000400000100430014000084c60a00001c760a0000000000000000000044000a3136303538313637313657000104f0e1')
else:
if bytes.hex(data) == '025451570007530004010000034c05':
valve = '01'
elif bytes.hex(data) == '025451570007530004010100037b35':
valve = '01'
dry = '01'
elif bytes.hex(data) == '025451570007530004000000033ab1':
valve = '00'
dry = '00'
data = bytes.fromhex('025441000000014c')
conn.sendall(data)
print('Connection closed')
print('Socket closed')