I am using C#.NET in order to interface with matlab for UDP communication (because i do not have the toolkit for matlab udp support). I made two C# classes (Client Class and Server Class) and built them to DLL's and imported them into matlab using NET.addAssembly();
What I do is:
- read a binary file (File1.bin) into a byte[] array
// C#
byte[] data = File.ReadAllBytes();
- Send the byte array using UDP sockets.
// C#
sendClient.Send(data, data.Length);
- Write the received datagram to another binary file (File2.bin)
In matlab:
% Receive data...
fd = fopen('File2.bin','w');
for i=1 through the length of data:
fprintf(fd, data(i));
My problem is when I use visdiff('File1.bin', 'File2.bin') in matlab to compare File1.bin and File2.bin, almost everything is identical except for a few (~30) bytes in File2.bin are replaced with 0x1A and I need these two files to be identical.
Any help or suggestions are appreciated!
Thanks
Note: This is done on a single machine in two different matlab windows.
If you need more info let me know. I cant copy and paste code because it is on a machine not internet accessible.
UPDATE:
After more debugging I have found that the problem occurs before any UDP datagrams are sent. Using C# ReadAllBytes() and Matlab fread() both output arrays contain these anomalous 0x1A, but I still do not know why...