-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtrackingclient.py
47 lines (39 loc) · 1.13 KB
/
trackingclient.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
import socket
import time
def connect(ip,port):
#make a client socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#keep trying to connect to the server until success
print("connecting to control server...")
connected = False
while not connected:
try:
s.connect((ip, port))
connected = True
except Exception as err:
pass
print("connected")
return s
def getPosition():
#compute it, or grab it from wherever it's store
return 1.0, 1.0, 1.0
def main():
ip = "127.0.0.1"
port = 7779
size = 1024
#first get a connection to the server
s = connect(ip,port)
#now just spin on the stream writing a position
while 1:
try:
x,y,z = getPosition()
msg = "" + `x` + "," + `y` + "," + `z` + "\n"
s.send(msg)
time.sleep(1)
except Exception as err:
print("disconnected")
#we got disconnected somehow, reconnect
s = connect(ip,port)
s.close()
if __name__ == "__main__":
main()