Difference between tcpclient and tcpip?

23 views (last 30 days)
Christian D
Christian D on 9 May 2016
Edited: RST on 5 Mar 2024 at 19:23
Hi folks,
What is the difference between tcpclient provided by the standard Matlab and tpcip provided by the Intrument control toolbox? I don't have that toolbox and want to communicate with a device over tcp (sending commands and recieving measurement values). I'm still not aware of the difference of both functions.
Regards, Christian

Answers (4)

srj4anoop
srj4anoop on 12 May 2016
Hi Christian,
With the tcpclient() function you can only create a TCP/IP client object. The syntax of using tcpclient() is as shown below :
>> tclient = tcpclient('Address',Port,'Timeout',<timeout_value>)
where the Timeout property specifies the waiting time to complete read and write operations in seconds, and the default is 10.
Whereas the tcpip() function lets you create a TCP/IP object that can be configured to work as a Server or as a Client using its NetworkRole property.
For example, to create a TCP/IP server object:
tcpipServer = tcpip('0.0.0.0',55000,'NetworkRole','Server');
and to create a TCP/IP client interface for the server socket:
tcpipClient = tcpip('127.0.0.1',55000,'NetworkRole','Client')
You can refer to the following blog to undertsand more about this function:

RST
RST on 4 Aug 2022
Edited: RST on 5 Mar 2024 at 19:23
In addition to the above it appears that:
tcpip
  • acts as a MATLAB fileID (similar to a C-language FILE*), so supports fread(), fgets(), fwrite(), fprintf(), etc
  • has a long (20 second?) connection timeout, that can not be changed. Please fix this, Mathworks!
tcpclient
  • acts more like a C-language integer file descriptor. In versions earlier than R2020b it only supports the low-level read() and write() functions. R2020b introduced: configureTerminator(), readline(), writeline() and configureCallback().
  • supports ConnectTimeout as an optional argument in the constructor
If at first you don't succeed: cheat. A work-around for the tcpip connection timeout issue is to attempt to make a tcpclient connection. If that fails then throw an error, otherwise delete the tcpclient and make a tcpip.

Walter Roberson
Walter Roberson on 12 May 2016
You might also be interested in the File Exchange contribution "tcpudpip"

Dev-iL
Dev-iL on 17 May 2016
  • tcpip can act both as a client and a server, requires the Instrument Control Toolbox and was last modified in R2011a.
  • tcpclient can only act as a client, doesn't require additional toolboxes (as far as I can tell) and was introduced later, that is in R2014b.

Products

Community Treasure Hunt

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

Start Hunting!