Controlling drivers with data received via TCP/UDP For a project I need to drive shape keys with data received via a network connection. In my setup I receive input form a TouchOSC app running on an iPad into PureData on a Mac. The input data then is processed and sent out over UDP to 127.0.0.1:13001.

That's all working fine but now I need Blender to receive the packets, evaluate them and use the values to drive properties on objects. In my case I need to drive the value property of shape keys.

Is this possible and if so, how can I approach this the best way?
The basic idea is to open a socket, poll the data and apply the received values to the shape keys:

import socket

# open network socket
port = 13001
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("127.0.0.1", port))
print "waiting on port:", port

# poll data (could use a timer)
data, addr = s.recvfrom(1024) 
print data
# set float value from data
# value convert from data
bpy.context.object.data.shape_keys.key_blocks['Key 1'].value = float(value)


Related: 


Mapping an algorithm to an animation
http://www.binarytides.com/programming-udp-sockets-in-python/
How to run a python script at regular intervals?