python - 使用 Blender Python 与纯数据的 TCP 连接

标签 python tcp network-programming blender puredata

我需要一些帮助来弄清楚我的代码,以便通过 TCP 连接将信息从 Blender 发送到 Pure Data。我有一个表面,上面有一个球在滚动,我需要获取球的速度及其碰撞,以便通过 TCP 将其发送到 Pd,以便将数据转换为程序音频。

我一直在寻找执行此操作的可能方法,由于我对 python 和编码的理解非常有限(刚刚开始),我发现很难看清发生了什么。

现在这是我的问题:

我知道我可以通过在 blender 中编写这个来发送一个简单的代码字符串,这对我很有用:

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())

而且我知道我可以使这段代码从我的对象中获取例如坐标:

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()

我需要弄清楚的是如何将该信息插入到 my.send 中,以便我可以在 Pure Data 中接收它。 我已经查看了有关如何进行这项工作的网站,但还没有找到我需要的东西。我想知道是否有人有一些可能与此有关的好消息来源,或者是否有人知道如何将我的 owner.getVelocity() 集成到 tcp 消息中?

最佳答案

编辑:

我想我自己解决了,我现在正在 PD 中获取数据流。

如果有人感兴趣,这是代码:

import bge
import socket




cont = bge.logic.getCurrentController()
owner = cont.owner
vel = owner.getVelocity()

x = (vel [0])
y = (vel [1])
z = (vel [2])

added = x+y+z
print (added)

tsr = str(added)     
tsr += ';'
host = '127.0.0.1'
port = 50007
msg = '123456;'

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.connect((host, port))

s.send(tsr.encode())

s.shutdown(0)

s.close()

感谢您的宝贵时间!

安德烈亚斯

关于python - 使用 Blender Python 与纯数据的 TCP 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13606219/

相关文章:

network-programming - 是否有任何标准 URL 用于检测强制门户的存在?

c++ - Delphi 中的 TClientDataSet.LoadFromStream() 中的 "Error creating variant or safe array"

python - 在谷歌应用程序引擎中加载cookie

python - 令人困惑的 python 星号符号的双重使用(作为函数参数,或作为函数定义)

python - 使用 appcfg.py 时出现意外的关键字参数 "context"

linux - 关于 INADDR_ANY 的问题

tcp - 端口重定向不适用于 IPtables

python - 最安全的服务器到服务器连接

c++ - (QNativeSocketEngine) QObject : Cannot create children for a parent that is in a different thread

python - 如何在 Python 中序列化 scandir.DirEntry 以通过网络套接字发送?