UDP Python - 尽管召回功能,数据仅发送一次

时间:2015-01-09 16:51:13

标签: python udp osc

我已经成功创建/改编了一个工作的OSC python脚本,该脚本可以接受外部硬件的OSC数据并将其打印到我的计算机上。

我目前正在尝试将此数据发送到另一个程序。该脚本正在运行,除了它只发送第一个UDP消息。在控制台中,我可以看到脚本正在工作,因为它在接收到osc数据时打印出代码的各个方面。

UDP接收器正在另一端工作,即将其他消息发送到外部程序。

包含可能有助于识别问题的代码部分。任何帮助是值得赞赏的,奇怪的是,该功能的其余部分再次被调用并正常工作,而不是发送数据的最后一行......

我确实尝试了一个单独的函数并在osc处理函数结束时调用该函数,但同样只发送第一条UDP消息的问题仍然存在。

提前致谢!



ip = socket.gethostbyname(socket.gethostname()) #Gets IP of MacBook Pro

receive_address = ip, 4567 # MacBook Pro Adress, Outgoing Port
send_address = '192.168.#.##', 9112 # iPhone Adress, Incoming Port
 
# ------------------ UDP to send  IP/ Port Settings ----------------- #


UDP_IP = "127.0.0.1" # Local machine to send data internally
UDP_PORT = 1234 # Local UDP Port

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((UDP_IP, UDP_PORT))


# --------------------- OSC Server and client start -------------------------------- #
 
# Initialize the OSC server and the client.
s = OSC.OSCServer(receive_address)
c = OSC.OSCClient()
c.connect(send_address)
 
s.addDefaultHandlers()

def multixy1(add, tags, stuff, source): #osc handler
	
	print "Message received:"
	msg = OSC.OSCMessage()
	print msg
	msg.setAddress(addr)
	msg.append(stuff)
	c.send(msg)
	
        # Testing osc is working/updating with each message input #
        print "Raw OSC Mesagge = ", msg
	print "X Value: ", stuff[0]

	UDP_to_Send = str(msg)
	
        print "UDP Send message = ", UDP_Send
	print sock
	print datetime.now()
	
        tm = str(datetime.now())
	print "size = ", sys.getsizeof(tm), "bytes"
	
        sock.send(tm) # this line does not appear to be called again despite the rest of the function being called

s.addMsgHandler("/1/fader1",  multixy1)

# ----------- Starting OSC server ----------- #

print "\nStarting OSCServer."

st = threading.Thread( target = s.serve_forever )
st.start()

# Loop while threads are running.
try :
    while 1 :
	time.sleep(0.1)
	
except KeyboardInterrupt :
    print "\nClosing OSCServer."
    s.close()
    print "Waiting for Server-thread to finish"
    st.join()
    print "Done"




0 个答案:

没有答案