Search code examples
pythonmatlabudpdata-transferreal-time-data

establish connection from python to matlab


I am trying to transfer data in real time from python to matlab using UDP protocol (as this post suggested: Real-time data transfer from Python to MATLAB).

right now this is what I have, and it dosent work:

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

on matlab (reciver):

u = udp('0.0.0.0','LocalPort',8821);
fopen(u);

while(1)
    A = fread(u,10);
end

fclose(u)

It dosent work, and the errors I get: from python: enter image description here

and from matlab:

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

any idieas?


Solution

  • It works for me if I actually tell socket that I want a UDP connection:

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

    (hat tip to https://wiki.python.org/moin/UdpCommunication)