Matlab tcpip server receiving data from c program

287 views Asked by At

I am trying to write a Matlab code that will receive data from an outside c program and graph it. The data is in text format. In my past attempts every time the connection is made, but no message is received by the matlab program even though I can verify that is was sent. Basically I am looking for an answer on the correct way in Matlab to retrieve data from a TCP connection that was sent from a c program.

function tcp_testing()
    t = tcpip('localhost',7220,'NetworkRole','server')

    % Set size of receiving buffer, if needed.
    set(t, 'InputBufferSize', 30000); 

    % Open connection to the server. 
    fopen(t); 

    % Transmit data to the server (or a request for data from the server). 
    fprintf(t, 'GET /'); 

    % Pause for the communication delay, if needed. 
    pause(1) 

    % Receive lines of data from server 
    while (get(t, 'BytesAvailable') > 0)
        t.BytesAvailable 
        DataReceived = fscanf(t) 
    end 
end
0

There are 0 answers