Main Content

TCP/IP Interface

Communication using the TCP/IP clients and servers

Transmission Control Protocol (TCP) is a transport protocol layered on top of the Internet Protocol (IP) and is one of the most used networking protocols. Instrument Control Toolbox™ support for TCP/IP communication includes the ability to create clients and servers. TCP/IP client support enables you to use network socket communication to connect to remote hosts from MATLAB® for reading and writing both binary and ASCII data. TCP/IP server support enables you to create a network socket for communication between MATLAB and a single client.

Use tcpclient to create a TCP/IP client that connects to a server or hardware and perform read and write operations. Use tcpip to create a TCP/IP server.


expand all

Connect and Configure

tcpclientCreate TCP/IP client connection with TCP/IP server
configureTerminatorSet terminator for ASCII string communication with remote host over TCP/IP
configureCallbackSet callback function and trigger condition for communication with remote host over TCP/IP

Read and Write

readRead data from remote host over TCP/IP
readlineRead line of ASCII string data from remote host over TCP/IP
readbinblockRead one binblock of data from remote host over TCP/IP
writeWrite data to remote host over TCP/IP
writelineWrite line of ASCII data to remote host over TCP/IP
writebinblockWrite one binblock of data to remote host over TCP/IP
writereadWrite command to remote host over TCP/IP and read response
flushClear buffers for communication with remote host over TCP/IP

Connect and Configure

tcpip(To be removed) Create TCPIP object
echotcpipStart or stop TCP/IP echo server
resolvehostNetwork name or network address

Read and Write

fopenConnect interface object to instrument
fcloseDisconnect interface object from instrument
freadRead binary data from instrument
fwriteWrite binary data to instrument
fscanfRead data from instrument, and format as text
fprintfWrite text to instrument
readasyncRead data asynchronously from instrument
stopasyncStop asynchronous read and write operations
binblockreadRead binblock data from instrument
binblockwriteWrite binblock data to instrument
fgetlRead line of text from instrument and discard terminator
fgetsRead line of text from instrument and include terminator
queryWrite text to instrument, and read data from instrument
scanstrRead data from instrument, format as text, and parse

Other Frequently Used

clearRemove instrument objects from MATLAB workspace
deleteRemove instrument objects from memory
instrhwinfoInformation about available hardware
instrfindRead instrument objects from memory to MATLAB workspace
instrfindallFind visible and hidden instrument objects
instrresetDisconnect and delete all instrument objects
flushinputRemove data from input buffer
flushoutputRemove data from output buffer
instrcallbackDisplay event information when event occurs


Query InstrumentQuery or read instrument data
To InstrumentSend simulation data to instrument
TCP/IP ReceiveReceive data over TCP/IP from specified remote machine
TCP/IP SendSend data over TCP/IP to specified remote machine


TCP/IP Communication

TCP/IP Communication Overview

Use network socket communication to connect to remote hosts from MATLAB for reading and writing data over TCP/IP.

TCP/IP and UDP Comparison

Compare the TCP/IP and UDP protocols to determine which to use.

TCP/IP Client

Create TCP/IP Client and Configure Settings

Connect to remote hosts or hardware from MATLAB for reading and writing data over TCP/IP.

Write and Read Data over TCP/IP Interface

Write and read data to and from the remote host connected to the tcpclient object.

Use Callbacks for TCP/IP Communication

Enhance TCP/IP communication by executing a callback function when a specified event occurs.

Transition Your Code to tcpclient Interface

Connect to serial port devices using tcpclient instead of tcpip.

TCP/IP Server

Communicate Using TCP/IP Server Sockets

Support for Server Sockets is available for a single remote connection. You can use this connection to communicate between a client and MATLAB, or between two instances of MATLAB.


Troubleshooting TCP/IP Communication

Troubleshoot the TCP/IP interface.

Resolve TCP/IP Client Warning: Unable to Read Any Data

Troubleshoot when you receive no data and you get the warning message: 'tcpclient' unable to read any data.

Featured Examples