Skip to content

Commit 1186287

Browse files
committed
Client side code from Finn
1 parent 06f811b commit 1186287

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

trackingclient.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import socket
2+
import time
3+
4+
def connect(ip,port):
5+
#make a client socket
6+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7+
#keep trying to connect to the server until success
8+
print("connecting to control server...")
9+
connected = False
10+
while not connected:
11+
try:
12+
s.connect((ip, port))
13+
connected = True
14+
except Exception as err:
15+
pass
16+
print("connected")
17+
return s
18+
19+
def getPosition():
20+
#compute it, or grab it from wherever it's store
21+
return 1.0, 1.0, 1.0
22+
23+
def main():
24+
ip = "127.0.0.1"
25+
port = 7779
26+
size = 1024
27+
28+
#first get a connection to the server
29+
s = connect(ip,port)
30+
31+
#now just spin on the stream writing a position
32+
while 1:
33+
try:
34+
x,y,z = getPosition()
35+
msg = "" + `x` + "," + `y` + "," + `z` + "\n"
36+
s.send(msg)
37+
time.sleep(1)
38+
except Exception as err:
39+
print("disconnected")
40+
#we got disconnected somehow, reconnect
41+
s = connect(ip,port)
42+
43+
s.close()
44+
45+
46+
if __name__ == "__main__":
47+
main()

0 commit comments

Comments
 (0)