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 serverendechotcpip('off');close all;clear all;clc;% Configuration and connectiondisp ('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');endfclose(server);disp('port closed');
Best Answer