TCP connection between too PCs
4 views (last 30 days)
Show older comments
Hello. I am a beginner in Matlab. I have a problem. I am new here. I hope my english is ok. I want to configure a TCP connection between two PC's. I use Matlab R2013a. My problem is i do not receive data completely. Only the last values. I want to send a sinus with 600 values. But i receive only 599. Sometimes i received much lesser. I hope, there is somebody who can help me. It would be very grateful.
Thanx
Here is my code (Server and Client) and a warning:
Code for the Server:
clear all();
t = tcpip('0.0.0.0',50000, 'NetworkRole', 'Server');
set(t, 'InputBufferSize',4000);
while(1)
try
fopen(t);
fprintf('TCP Socket open');
break;
catch
fprintf('TCP Socket not open');
end
end
%connectionServer = t;
pause(1);
data = fread(t,600, 'float32');
get(t, 'ValuesReceived')
fclose(t);
code for the Client
d = tcpip('192.168.101.103', 50000, 'NetworkRole', 'Client');
set(d, 'OutputBufferSize', 4000);% Set size of receiving buffer, if needed.
%Trying to open a connection to the server.
while(1)
try
fopen(d);
fprintf('%s \n','Server found');
break;
catch
fprintf('%s \n','Server not found');
end
end
x= (0:599).*8*pi/1000;
data=sin(x);
for i=1:600
fwrite(d,data(i),'float32');
get(d, 'ValuesSent')
end
fprintf('%s \n','Data send');
fclose(d);
Warning
Warning: Unsuccessful read: The specified amount of data was not returned within the Timeout period.
0 Comments
Answers (1)
Walter Roberson
on 21 Jan 2014
You should configure Byte mode and be sure that Terminator is disabled.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!