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 tcpserver to create a TCP/IP server.

Functions

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 (Since R2020b)
configureCallbackSet callback function and trigger condition for communication with remote host over TCP/IP (Since R2020b)
tcpclientfindFind TCP/IP client connections (Since R2024a)

Read and Write

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

Connect and Configure

tcpserverCreate TCP/IP server (Since R2021a)
configureTerminatorSet terminator for ASCII string communication (Since R2021a)
configureCallbackSet callback function and trigger condition for communication (Since R2021a)
tcpserverfindFind TCP/IP servers (Since R2024a)

Read and Write

readRead data sent to TCP/IP server (Since R2021a)
readlineRead line of ASCII string data sent to TCP/IP server (Since R2021a)
readbinblockRead one binblock of data sent to TCP/IP server (Since R2021a)
writeWrite data from TCP/IP server (Since R2021a)
writelineWrite line of ASCII data from TCP/IP server (Since R2021a)
writebinblockWrite one binblock of data from TCP/IP server (Since R2021a)
flushClear buffers for communication using TCP/IP server (Since R2021a)
resolvehostResolve network host name or IP address
echotcpipStart or stop TCP/IP echo server

Apps

TCP/IP ExplorerConnect to and communicate with TCP/IP server (Since R2021b)

Blocks

TCP/IP ReceiveReceive data over TCP/IP network from specified remote machine
TCP/IP SendSend data over TCP/IP network to specified remote machine

Topics

TCP/IP Communication

TCP/IP Client

TCP/IP Server

TCP/IP Explorer App

Troubleshooting

Troubleshooting TCP/IP Client Interface

Troubleshoot the TCP/IP client interface.

Resolve TCP/IP Client Connection Errors

Troubleshoot creating a TCP/IP client.

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.

Troubleshooting TCP/IP Server Interface

Troubleshoot the TCP/IP server interface.

Resolve TCP/IP Server Connection Errors

Troubleshoot creating a TCP/IP server.

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

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

Resolve TCP/IP Server Warning: Unable to Read All Data

Troubleshoot when you receive some data and you get the warning message: 'tcpserver' unable to read all requested data.

Featured Examples