41 lines
No EOL
984 B
Python
41 lines
No EOL
984 B
Python
import socket
|
|
import math
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
host =""
|
|
port =30002
|
|
s.bind((host,port))
|
|
s.listen(1) # Number of connections
|
|
s.setblocking(False)
|
|
|
|
client = None
|
|
while True:
|
|
try:
|
|
client, address = s.accept()
|
|
print("Connected to", address)
|
|
|
|
except socket.error:
|
|
pass
|
|
|
|
if client is not None:
|
|
try:
|
|
data = client.recv( 1024 ).decode( 'utf-8' )
|
|
if data:
|
|
lastdata=data.split('\n')
|
|
#print("Received :", repr(data))
|
|
if (len(lastdata)>1):
|
|
splitdata=lastdata[-2].split(",")
|
|
|
|
try:
|
|
pan=float(splitdata[0])
|
|
tilt=float(splitdata[1])
|
|
print("Pan="+str(pan)+" Tilt="+str(tilt))
|
|
except ValueError:
|
|
print("Not a float")
|
|
except socket.error:
|
|
pass
|
|
|
|
|
|
|
|
|
|
s.close() |