tcpclient
Create TCP/IP client connection with TCP/IP server
Description
A tcpclient
object represents a connection to a remote host
and remote port from MATLAB® to read and write data. The remote host can be a server or hardware that
supports TCP/IP communication, and must already exist. The tcpclient
object is always the client and cannot be used as a server. For information on creating a
TCP/IP server, see Communicate Using TCP/IP Server Sockets.
Creation
Description
creates a TCP/IP client that connects to a server associated with the remote host
t
= tcpclient(address
,port
)address
and remote port port
. The value
of address
can be either a remote host name or a remote host IP
address. The value of port
must be a number between 1 and 65535.
The input address
sets the Address
property and the
input port
sets the Port
property.
If you specified an invalid address or port, the TCP/IP server is not running, or the connection to the server cannot be established, then the object is not created and MATLAB throws an error.
creates a connection and sets additional Properties using one or
more name-value pair arguments. Set the t
= tcpclient(address
,port
,Name,Value
)Timeout
, ConnectTimeout
, and
EnableTransferDelay
properties using name-value pair arguments. Enclose each property name in quotes,
followed by the property value.
Example: t =
tcpclient("144.212.130.17",80,"Timeout",20,"ConnectTimeout",30)
creates
a TCP/IP client connection to the TCP/IP server on port 80 at IP address
144.212.130.17. It sets the timeout period to 20 seconds and the connection timeout
to 30 seconds.
Properties
Object Functions
read | Read data from remote host over TCP/IP |
readline | Read line of ASCII string data from remote host over TCP/IP |
readbinblock | Read one binblock of data from remote host over TCP/IP |
write | Write data to remote host over TCP/IP |
writeline | Write line of ASCII data to remote host over TCP/IP |
writebinblock | Write one binblock of data to remote host over TCP/IP |
writeread | Write command to remote host over TCP/IP and read response |
configureTerminator | Set terminator for ASCII string communication with remote host over TCP/IP |
configureCallback | Set callback function and trigger condition for communication with remote host over TCP/IP |
flush | Clear buffers for communication with remote host over TCP/IP |
delete | Remove instrument objects from memory |
clear | Remove instrument objects from MATLAB workspace |