我正在尝试使用UDP协议将数据从python实时传输到matlab(如本文建议:Real-time data transfer from Python to MATLAB)。
现在这就是我所拥有的,它起作用了:
on python(sender):
import socket
my_socket= socket.socket()
my_socket.connect(('127.0.0.1', 8821))
MESSAGE='test1'
for i in range(1,10):
my_socket.send(MESSAGE)
print i
my_socket.close
在matlab上(reciver):
u = udp('0.0.0.0','LocalPort',8821);
fopen(u);
while(1)
A = fread(u,10);
end
fclose(u)
来自matlab:
Warning: Unsuccessful read: The specified amount of data
was not returned within the Timeout period.
任何idieas?
答案 0 :(得分:4)
如果我实际告诉socket
我想要UDP连接,它对我有用:
my_socket= socket.socket(socket.AF_INET, socket.SOCK_DGRAM)