MATLAB Answers

How to Transfer Image file from server to client using TCP IP ?

조회 수: 56(최근 30일)
Selva Karna
Selva Karna 31 Mar 2018
답변: Zdenek Kubin 8 Jun 2018
How to Transfer Image file from server to client using TCP IP ?

답변(1개)

Zdenek Kubin
Zdenek Kubin 8 Jun 2018
Hi, some time ago I download from this exchange this code:
Server:
data =imread('ngc6543a.jpg');
data=im2double(data);
s = whos('data');
s.size;
s.bytes;
tcpipServer = tcpip('...', 30000, 'NetworkRole', 'Server');
set(tcpipServer, 'OutputBufferSize', s.bytes);
fopen(tcpipServer);
fwrite(tcpipServer, data(:), 'double');
fclose(tcpipServer);
Client:
tcpipClient = tcpip('...',30000);
set(tcpipClient,'InputBufferSize',300000);
set(tcpipClient,'Timeout',5); %Waiting time in seconds to complete read and write operations
fopen(tcpipClient);
get(tcpipClient, 'BytesAvailable');
tcpipClient.BytesAvailable
DataReceived =[];
pause(0.1);
while (get(tcpipClient, 'BytesAvailable') > 0)
tcpipClient.BytesAvailable
rawData = fread(tcpipClient,300000/8,'double');
DataReceived = [DataReceived; rawData];
pause(0.1)
end
fclose(tcpipClient);
delete(tcpipClient);
clear tcpipClient
% ploting
reshapedData = reshape(DataReceived,650,600,3);
imshow(reshapedData)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by