File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
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 ()
You can’t perform that action at this time.
0 commit comments