主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

TCP/IP 接口

使用 TCP/IP 客户端和服务器进行通信

传输控制协议 (TCP) 是位于互联网协议 (IP) 之上的传输协议,也是最常用的网络协议之一。Instrument Control Toolbox™ 对 TCP/IP 通信的支持包括创建客户端和服务器的能力。TCP/IP 客户端支持使您能够使用网络套接字通信从 MATLAB® 连接到远程主机,以读取和写入二进制和 ASCII 数据。TCP/IP 服务器支持使您能够创建一个网络套接字,用于 MATLAB 和单个客户端之间的通信。

使用 tcpclient 创建一个连接到服务器或硬件并执行读写操作的 TCP/IP 客户端。使用 tcpserver 创建 TCP/IP 服务器。

函数

全部展开

连接和配置

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
tcpclientfindFind TCP/IP client connections (自 R2024a 起)

读取和写入

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

连接和配置

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

读取和写入

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

App

TCP/IP 通信管理器Connect to and communicate with TCP/IP server (自 R2021b 起)

模块

TCP/IP Receive通过 TCP/IP 网络从指定的远程机器接收数据
TCP/IP SendSend data over TCP/IP network to specified remote machine

主题

TCP/IP 通信

TCP/IP 客户端

TCP/IP 服务器

TCP/IP 通信管理器

疑难解答

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.

精选示例