Wrong and Excessive values are received by the Host Server MATLAB while communicating Via TCP/IP Server Socket with Client Server MATLAB installed at different computer.

조회 수: 3 (최근 30일)
I was trying to transfer data via TCP/IP Server Socket communication between two different version of MATLAB installed in two different computers. The Server computer has MATLAB version 2016a installed and the Client server has MATLAB 2021a installed in it.
The code for MATLAB (R2016a) Host Server is as follows:
server = tcpip('0.0.0.0', 10000, 'NetworkRole', 'server')
fopen(server)
The code for MATLAB (R2021a) Client Server is as follows:
client = tcpclient("172.26.45.99",10000)
client =
tcpclient with properties
Address: '172.26.45.99'
Port: 10000
NumBytesAvailable: 0
Show all properties, functions
data = [1 2 3 4 5];
write(client,data)
The code for MATLAB (R2016a) Host Server is as follows:
read_data = fread(server,server.BytesAvailable)
After running this code in host server machine the variable size "read_data" becomes 40 x 1 double instead of 5 x 1. The values received were attached with this mail. I donot have any clue why values are comming as wrong and to excessive. Can anyone guide me why such abnormal data is receiving by the host server?

채택된 답변

Nadia Shaik
Nadia Shaik 2022년 4월 7일
Hello Sourav,
It is my understanding that the expected data size is not received at the server while using ‘tcpip’ function for server computer in MATLAB R2016a and ‘tcpclient’ function for client server in MATLAB R2021a.
You may usetcpclient’ or ‘tcpserver’ instead of ‘tcpip’ function as mentioned in the documentation.
Hope it helps!
  댓글 수: 2
Souarv De
Souarv De 2022년 4월 7일
@Nadia Shaik But In MATLAB R2016a there is no function called 'tcpserver' unlike MATLAB R2021a to create Server object. In MATLAB R2016a, 'tcpclient' function is there but with this function I think we can only create client object. So if I have two computers and I want to use the MATLAB R2016a as a server then what is the way (without use of 'tcpip') to make a server object there?
Nadia Shaik
Nadia Shaik 2022년 4월 11일
Hello Sourav,
As 'tcpip' function will be removed in the future releases, for compatibility reasons I would suggest you to kindly upgrade the MATLAB version to R2021a and use 'tcpserver' function to create Host Server.
Hope it helps!

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by