I'm trying to send data back and forth between a Matlab app and a C++ app. The data is comprised of a 100 char array. Both apps are on the same computer. The Matlab app in this case is the Server and the C++ is the client.
I am able to receive data properly in the direction from my C++ app to Matlab. However I am not able to receive the data in the opposite direction from Matlab to my C++ app, though I'm using exactly the same socket.
I checked my C++ app, by using a second C++ application that talks to the first one through the same UDP interface and the data was transmitted back and forth properly.
Just for testing the connection, I'm trying to send a 100 char array with 'A' in the first cell from C++ to Matlab, and return a 100 char array with 'I' in the first cell from Matlab to C++:
CPP_IP = '127.0.0.1';
CPP_Port = 817;
OpenCPP = udp(CPP_IP,CPP_Port,'LocalPort',CPP_Port);
OpenCPP.InputBufferSize = 100;
OpenCPP.OutputBufferSize = 100;
OpenCPP.ByteOrder = 'littleEndian';
OpenCPP.Timeout = 30;
CPP_Connection = 0;
fprintf('waiting for CPP to come alive...')
msg = fscanf(OpenCPP,'%c',[100 1]);
if OpenCPP.ValuesReceived == 100
if msg(1) == 'A'
fprintf('\nCPP alive and connected!\n')
CPP_Connection = 1;
fprintf('Command from CPP incomplete!')
msg(1) = 'I';
When running this code and my C++ app, if I check the connection properties after receiving the letter 'A', this is what I get:
UDP Object : UDP-127.0.0.1
I received 100 chars as expected and sent 100 chars. It looks like the sent data is not actually read by the C++, although as I said, the interface on the C++ app was checked with another C++ app and worked fine.
It seems like an issue in the communication between Matlab and C++
Any help would be highly appreciated!