建立从python到matlab的连接

时间:2016-02-05 15:27:00

标签: python matlab udp data-transfer real-time-data

我正在尝试使用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)

它起作用,我得到的错误: 来自python: enter image description here

来自matlab:

Warning: Unsuccessful read:  The specified amount of data 
was not returned within the Timeout period. 

任何idieas?

1 个答案:

答案 0 :(得分:4)

如果我实际告诉socket我想要UDP连接,它对我有用:

my_socket= socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

(帽子提示为https://wiki.python.org/moin/UdpCommunication