Matlab 同一网络上两台计算机之间的TCP/IP协议

Matlab 同一网络上两台计算机之间的TCP/IP协议,matlab,networking,tcp,Matlab,Networking,Tcp,我正在尝试使用Matlab中的TCP将一些位数据从一台计算机发送到同一网络上的另一台计算机 目前这是我用来打开连接的设置。我试图模拟点对点连接,因为它们需要互相发送和接收数据。当我使用IPv4和IPv6运行本地计算机时,它可以在本地计算机上正常工作 %code starts in one file openRecieve('0.0.0.0', 3000); %accept all connections openSend('10.32.41.235',3000); 然后我在另一个文件中

我正在尝试使用Matlab中的TCP将一些位数据从一台计算机发送到同一网络上的另一台计算机

目前这是我用来打开连接的设置。我试图模拟点对点连接,因为它们需要互相发送和接收数据。当我使用IPv4和IPv6运行本地计算机时,它可以在本地计算机上正常工作

 %code starts in one file
 openRecieve('0.0.0.0', 3000); %accept all connections
 openSend('10.32.41.235',3000); 
然后我在另一个文件中执行同样的操作,我可以在我的计算机上并行运行它们:

%code starts in other file
openSend('10.32.41.235',3000); %IPv4 of PC
openRecieve('0.0.0.0', 3000); %accept all connections 
IP是假的。。。。。。这段代码在我的机器上运行时使用两个不同的MatlabOpen实例。但是,它不能在两台不同的计算机之间工作

openReceive的代码:

function connectionServer = openRecieve(client, port)
t = tcpip('0.0.0.0', port, 'NetworkRole', 'Server');
set(t, 'InputBufferSize', 3000000); 
% Open connection to the client.
fopen(t);
fprintf('%s \n','Client Connected');
connectionServer = t;
set(connectionServer,'Timeout',.1);
end
openSend的代码:

function connectionSend = openSend(host, port)
d = tcpip(host, port, 'NetworkRole', 'Client');
set(d, 'OutputBufferSize', 3000000); % Set size of receiving buffer, if needed. 

%Trying to open a connection to the server.
while(1)
    try 
        fopen(d);
        break;
    catch 
        fprintf('%s \n','Cant find Server');
    end
end
connectionSend = d;
end

感谢您的帮助

它现在正在运行,尽管我唯一更改的是端口号从3000和3000改为3000和3001。。。。。。。。。。另外,只使用IPv4非常关键,因为我的网络不允许IPv6

对于任何试图在Matlab中编写TCP代码的人,只要使用“0.0.0.0”进行连接,如果您不关心谁在连接,因为它将接受所有试图在该端口上连接的IP#

第一个文件的当前代码:

sConec = openSend('10.234.24.124', 3000); %IPv4 Address of comp your trying to connect to
rConec = openRecieve('0.0.0.0', 3001); %Accept all connections
第二个文件的当前代码:

rConec = openRecieve('0.0.0.0', 3000); %Accept all connections
sConec = openSend('10.109.22.142', 3001); %IPv4 Address of computer your trying to connect to

这两台计算机能相互ping吗?它不工作是什么样子的?您会收到什么错误消息?我注意到一件事——您设置了一个非常短的超时
set(connectionServer,'timeout',.1)-这是个好主意吗?不确定单位是多少,但如果是ms,你不会给自己太长时间。。。两台计算机可能需要100多人才能在网络上找到对方…@Floris超时更多的是读/写,甚至在计算机连接后才会应用…@Slayton他们可以在IPV4上ping,但不能在IPV6上ping,因为我的网络上显然没有启用。