This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

tcpip

Create TCPIP object

Syntax

t = tcpip(RemoteHost)
t = tcpip(RemoteHost,RemotePort)
t = tcpip(___,Name,Value)

Description

example

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

When the TCPIP object is created, its Status property value is closed. When the object is connected to the host with the fopen function, the Status property is configured to open.

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

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

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 Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,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.

Introduced before R2006a