matlab使用TCP/IP Server Sockets
阿新 • • 發佈:2019-01-02
server 與 client 通訊:(image)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % server close all;clear all;clc; data =imread('img.jpg'); data=im2double(data); s = whos('data') s.size s.bytes tcpipServer = tcpip('0.0.0.0',30000,'NetworkRole','Server'); set(tcpipServer,'OutputBufferSize',s.bytes); fopen(tcpipServer); fwrite(tcpipServer,data(:),'double'); fclose(tcpipServer); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % client close all;clear all;clc; tcpipClient = tcpip('127.0.0.1',30000,'NetworkRole','Client') set(tcpipClient,'InputBufferSize',4500000); set(tcpipClient,'Timeout',30); fopen(tcpipClient); rawData = fread(tcpipClient,562500,'double'); fclose(tcpipClient); reshapedData = reshape(rawData,375,500,3); imshow(reshapedData) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
matlab藉助java類,實現server 與 client 通訊: