TCP server in local network stays busy forever

조회 수: 7 (최근 30일)
Sami Al-Khayat
Sami Al-Khayat 2018년 4월 5일
댓글: Sami Al-Khayat 2018년 10월 26일
I'm trying to build a TCP connection between two PCs in my local network. The code for the server looks like this:
tcp_server = tcpip('192.168.xxx.yyy', 30000, 'NetworkRole', 'server');
tcp_server.BytesAvailableFcnMode = 'terminator';
tcp_server.Terminator = 19;
fopen(tcp_server);
The code for my client looks like this:
tcp_client = tcpip('192.168.xxx.yyy', 30000, 'NetworkRole', 'client');
fopen(tcp_client);
fwrite(tcp_client,'hello world');
When I start the code on localhost (using 127.0.0.1 as IP adress) it has no problem working. The instance of MATLAB that's running stays busy until the client connects and then I can begin sending packages back and forth.
When using this same code on the local network between different machines though, the MATLAB instance running the server just stays busy, even after the client has connected. It's like it just freezes up.
I know for sure that the TCP over the network works, because I can connect two PC via TCP using the same network adresses using some C# code that I wrote. So the problem defenetly lies in MATLAB. Also connecting my C# server on one computer to a MATLAB client on another works flawlessly. It's just MATLAB server getting stuck in "Busy" when trying to connect via Network.

답변 (3개)

sen sun
sen sun 2018년 10월 22일
i am faced with similar problem,have you solved you problem? i will appreciate that you can give me some idea or advice.
  댓글 수: 4
sen sun
sen sun 2018년 10월 25일
maybe firewall is the keypoint.close firewall when using tcp/ip.
Sami Al-Khayat
Sami Al-Khayat 2018년 10월 26일
I've tried this before with no sucess, on different machines and different networks as well.
You mentioned that your problem is similar. What problem do you have, maybe we can come up with a solution that works for us both if we're stuck on a similar problem.

댓글을 달려면 로그인하십시오.


sen sun
sen sun 2018년 10월 26일
firewall(status:open) lead to communication failure.when i close firewall,they run successfully,can send and receive date correctly. i copy your code,and run on my computer.they run successfully
tcp_s = tcpip('0.0.0.0', 30000, 'NetworkRole', 'server');
tcp_s.BytesAvailableFcnMode = 'terminator';
tcp_s.Terminator = 19;
fopen(tcp_s);
tcp_c = tcpip('localhost', 30000, 'NetworkRole', 'client');
fopen(tcp_c);
fwrite(tcp_c,'hello world');

sen sun
sen sun 2018년 10월 26일
even using two computers,each one run server or client code,they can communicate successfully. tcp_s = tcpip('0.0.0.0', 30000, 'NetworkRole', 'server'); tcp_s.BytesAvailableFcnMode = 'terminator'; tcp_s.Terminator = 19; fopen(tcp_s); tcp_c = tcpip('IPV4 address',30000,'NetworkRole','client'); fopen(tcp_c); fwrite(tcp_c,'hello world');
  댓글 수: 1
Sami Al-Khayat
Sami Al-Khayat 2018년 10월 26일
I just tried that again. I closed firewall on both machines and tried connecting my C# client to my MATLAB server, both running basically the code above. No sucess, MATLAB stays busy forever, eventhough my C# client seems to be connected to the server. And as before when I create a C# server and connect a MALAB Client it works perfectly fine.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by