Why cannot communicate more than twice between server and client?
Show older comments
I want to construct more than twice communication between server and client.
I make two code Client and Server.
I achieve a single communication, but I cannot second communication.
Error message is "icinterface/fopen (line 83) Unsuccessful open: Connection refused: connect"
Client Code :
clc;
clear ;
close all;
% Configuration and connection
client = tcpip('localhost',30000,'NetworkRole','client');
disp('Wating for connection');
% Open socket and wait before sending data
fopen(client);
disp('Connection OK');
disp('Send Data')
fwrite(client, 'test')
disp('Complete send')
fclose(client);
delete(client);
clear client
Server Code :
%% TCP/IP Receiver
% Clear console and workspace
try
delete(server);
clear server
end
echotcpip('off');
close all;
clear all;
clc;
% Configuration and connection
disp ('Receiver started');
server=tcpip('localhost', 30000,'NetworkRole','server');
set(server, 'Timeout',inf);
set(server, 'InputBufferSize', 300000);
% Wait for connection
disp('port open. Waiting for connection');
fopen(server);
while true
while server.BytesAvailable == 0
end
% Read data from the socket
DataReceived=fread(server,server.BytesAvailable);
disp(strcat(char(DataReceived)'));
disp('Connection OK');
disp('complete read data');
end
fclose(server);
disp('port closed');
Accepted Answer
More Answers (0)
Categories
Find more on TCP/IP Communication in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!