How to create TCP IP Server in MATLAB R2020b without using tcpip command as it states it is not recommended.
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
It is very shocking to see that unlike MATLAB R2021a, in MATLAB 2020b there is no "tcpserver" matlab command exists. There is only one command i.e "tcpclient". "tcpip" command is there in MATLAB 2020b, but in it's documention part it's is written that this command is not recommended starting from R2020b and will be removed.
If this so, then how one can create a TCP server in that machine?
Risposte (1)
Walter Roberson
il 5 Ott 2022
tcpserver was introduced in R2021a .
You appear to be asking what should have been used in R2020b -- the release before tcpserver() was introduced.
If I understand correctly you do not want to use tcpip in R2020b (which was before tcpserver() was introduced) because of the compatibility note that that tcpip() will eventually be removed.
Imagine that Mathworks went back and retroactively introduced tcpserver() into R2020b to avoid this issue -- that it re-issued R2020b. Then when it did it would need to warn ahead of that that tcpip() would be eventually removed, so it would have to warn in R2020a. And then the same problem would occur for R2020a, so MATLAB would have to retroactielly introduce tcpserver() in R2020a, which would require notice in R2019b, but then the people running R2019b would have the same problem.... By induction, Mathworks would need to re-issue every version of MATLAB back to the very first release that introduced tcpip(), offering the alternative of tcpserver() in every old release, along with the warning that eventually, more than 15 years in the future, tcpip() would be withdrawn.
That is not going to happen.
It follows that the only alternative that would be acceptable for you is if Mathworks were to now declare that tcpip() will be retained in all future releases. That is not likely to happen.
If you have a reason to do active new development in an old release knowing that the implementation details of something are going to change, then a good way to do that is to write wrapper functions, something like
function obj = tcp_server_create(host, port)
if verLessThan('instrument', '4.3')
%user is running R2020a or earlier
obj = tcpip(host, port, 'Networkrole', 'server');
else
obj = tcpserver(host, port);
end
end
function tcp_server_open(obj)
if verLessThan('instrument', '4.3')
%user is running R2020a or earlier
fopen(obj)
else
%user is running R2020b or later
%do nothing, tcpserver() automatically opened the port
end
end
function data = tcp_server_read(varargin) %obj or obj, count
if verLessThan('instrument', '4.3')
%user is running R2020a or earlier
data = fread(varargin{:});
else
%user is running R2020b or later
data = read(varargin{:});
end
end
and so on. Then use those in the code. You would then be isolating the changes to a small number of routines that take care of detecting what function needs to be used internally.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!