【问题标题】:MATLAB sending image matrix on the networkMATLAB在网络上发送图像矩阵
【发布时间】: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


    【解决方案1】:

    您应该指定以下内容:

    set(t, 'OutputBufferSize', 3200);

    3200 值是您允许使用 tcp 发送的数据量。默认为512

    让我运行它,我会再次发布完整的答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多