Here is the patch:
And here is the script:
UDP_IP = 'localhost'
UDP_PORT = 3000
BUFFER_SIZE = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((UDP_IP, UDP_PORT))
print("waiting... ")
...
while True:
data, addr = s.recvfrom(1024)
print "received: ", data
val = float(data[:-2])
slp = int(val)
if val < 0.3:
lft()
#time.sleep(.01)
elif val > -0.3:
rgt()
#time.sleep(1)
else:
stop()
time.sleep(.5)
As an addendum, it seems that if I run the Python script first, then start the Pd patch, it works fine. If I do it the other way around, I get the error.