Main Content

tcpip

(To be removed) Create TCPIP object

tcpipand its object properties will be removed. Usetcpclientortcpserverand its properties instead. For more information, seeCompatibility Considerations

Description

example

t= tcpip(RemoteHost)creates a TCPIP object,t, associated with remote hostRemoteHostand the default remote port value of 80.

When the TCPIP object is created, itsStatusproperty value isclosed。When the object is connected to the host with thefopenfunction, theStatusproperty is configured toopen

The default local host in multihome hosts is the system default. TheLocalPortproperty defaults to a value of[], which allows any free local port to be used.LocalPortis assigned whenfopenis issued.

t= tcpip(RemoteHost,RemotePort)creates a TCPIP object with the specified remote port valueRemotePort

t= tcpip(___,Name,Value)creates a TCPIP object with the specified optional name-value pairs. If an invalid property name or property value is specified, the object is not created.

Examples

collapse all

Use a TCPIP object to write to an echo server and read back the message.

Start a TCP/IP echo server and create a TCPIP object.

echotcpip('on',4012) t = tcpip('localhost',4012);

Connect the TCPIP object to the host.

fopen(t)

Write to the host and read from the host.

fwrite(t,65:74) A = fread(t,10)
A = 65 66 67 68 69 70 71 72 73 74

Disconnect the TCPIP object from the host and stop the echo server.

fclose(t) echotcpip('off')

Input Arguments

collapse all

Remote host ID, specified as a character vector or string, identifying IP address or host name.

Example:'127.0.0.1'

Data Types:char|string

Port on remote host, specified as a numeric integer value from 1 to 65535.

Example:8001

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64

Name-Value Arguments

Specify optional comma-separated pairs ofName,Valuearguments.Nameis the argument name andValueis the corresponding value.Namemust appear inside quotes. You can specify several name and value pair arguments in any order asName1,Value1,...,NameN,ValueN

Example:'NetworkRole','server'

Network role for TCPIP object, specified as'client'or'server'。For example,t= tcpip('localhost',30000,'NetworkRole','server')creates a TCPIP object,t, that is an interface for a server socket.

Example:'server'

Data Types:char|string

Name of interface object, specified as a character vector or string.

Example:'TCPdev1'

Data Types:char|string

Time limit in seconds for communication, specified as a numeric value. The default is 10 seconds.

Example:60

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64

Output Arguments

collapse all

TCPIP interface, returned as an interface object.

Compatibility Considerations

expand all

Not recommended starting in R2020b

Introduced before R2006a