-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_client.py
46 lines (38 loc) · 941 Bytes
/
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
import socket
import select
import time
# 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():
try:
while isConnected:
# request
s.sendall(b'request')
print("request sent")
# wait
while not select.select([s], [], [], 0.01)[0]:
print("\twait for response")
time.sleep(1.0)
# responded
data = s.recv(1024)
data = data.decode("utf-8")
print("\tResponded:", data)
except KeyboardInterrupt:
print("done")
if __name__ == "__main__":
main()