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 views (last 30 days)
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('', 10000, 'NetworkRole', 'server')
The code for MATLAB (R2021a) Client Server is as follows:
client = tcpclient("",10000)
client =
tcpclient with properties
Address: ''
Port: 10000
NumBytesAvailable: 0
Show all properties, functions
data = [1 2 3 4 5];
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?

Accepted Answer

Nadia Shaik
Nadia Shaik on 7 Apr 2022
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!
Nadia Shaik
Nadia Shaik on 11 Apr 2022
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!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!