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は偽物です...... このコードは、2つの異なるmatlabインスタンスを開いた状態で実行すると、私のマシンで機能します。ただし、2 台の異なるコンピューター間では機能しません。
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
どんな助けでも大歓迎です。