I need some help figuring out my code for sending info from Blender through TCP connection to Pure Data. I have a surface with a ball rolling around on it and I need to grab the speed of the ball and its collisions in order to send it over TCP to Pd in order to convert data into procedural audio.
I have been looking at possible ways of doing this and due to my very limited understanding of python and coding so far (just began) I am finding it very hard to see whats going on.
Now heres my question:
I know that i can send a simple string of code by writing this in blender, which worked for me:
import socket
host ='127.0.0.1'
port = 50007
msg = '345;'
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((host,port))
s.send(msg.encode())
And i know that i can make this code to get e.g the coordinates from my object:
import bge
def main():
cont = bge.logic.getCurrentController()
owner = cont.owner
vel = owner.getVelocity()
x = (vel [0])
y = (vel [1])
z = (vel [2])
print (x+y+z)
main()
What I need to figure out is how to insert that information into my.send so I can receive it in Pure Data. I have looked at websites on how to make this work but havent found what i needed. I am wondering if anyone has some good sources that might concern this, or if anyone knows how to integrate my owner.getVelocity() into the tcp message?