【发布时间】:2015-04-19 18:54:50
【问题描述】:
我想创建一个 TCP/IP 会话,在其中我在服务器会话和客户端会话之间发送一个图像矩阵。
我的服务器会话的代码:
A = imread('cameraman.jpg');
[r, c]=size(A);
B = reshape(A,1,[]);%2d to 1d;
t = tcpip('0.0.0.0', 30000, 'NetworkRole', 'server');
fopen(t);
fwrite(t, B);
我的客户会话的代码:
t = tcpip('localhost', 30000, 'NetworkRole', 'client');
fopen(t);
data = fread(t, t.BytesAvailable);
C=reshape(data,r,c)%1d to 2d;
imshow(C);
我打开了两个 MATLAB 窗口并运行它们,首先是服务器。
问题是服务器程序一直在运行而没有连接到客户端:
>> tcpserver
Error using icinterface/fwrite (line 193)
The number of bytes written must be less than or equal to OutputBufferSize-BytesToOutput.
Error in tcpserver (line 6)
fwrite(t, B);
而客户端程序报错:
>> tcpclient
Error using icinterface/fread (line 163)
SIZE must be greater than 0.
Error in tcpclient (line 3)
data = fread(t, t.BytesAvailable);
【问题讨论】:
标签: matlab session image-processing network-programming