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.


Create TCPIP object


obj = tcpip('RemoteHost')
obj = tcpip('RemoteHost',RemotePort)
obj = tcpip(...,'PropertyName',PropertyValue,...)
obj = tcpip('localhost', 30000, 'NetworkRole', 'client')



The remote host.


The remote port.


Enables support for Server Sockets, using two values, client or server, to establish a connection as the client or the server.


A TCPIP property name.


A property value supported by PropertyName.


The TCPIP object.


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

obj = tcpip('RemoteHost',RemotePort) creates a TCPIP object with remote port value RemotePort.

obj = tcpip(...,'PropertyName',PropertyValue,...) creates a TCPIP object with the specified property name/property value pairs. If an invalid property name or property value is specified, the object is not created.

obj = tcpip('localhost', 30000, 'NetworkRole', 'client') creates a TCPIP object, obj, that is a client interface for a server socket.


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

t = tcpip('localhost',4012);

Connect the TCPIP object to the host.


Write to the host and read from the host.

A = fread(t, 10);

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



At any time, you can use the instrhelp function to view a complete listing of properties and functions associated with TCPIP objects.

instrhelp tcpip

When you create a TCPIP object, these property values are automatically configured:

  • Type is given by tcpip.

  • Name is given by concatenating TCPIP with the remote host name specified in the tcpip function.

  • RemoteHost and RemotePort are given by the values specified in the tcpip function.

You can specify the property names and property values using any format supported by the set function. For example, you can use property name/property value cell array pairs. Additionally, you can specify property names without regard to case, and you can make use of property name completion. For example, the following commands are all valid.

t = tcpip('','InputBufferSize',1024);
t = tcpip('','inputbuffersize',1024);
t = tcpip('','INPUT',1024);

When the TCPIP object is constructed, the Status property value is closed. Once 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's default. The LocalPort property defaults to a value of [] and it causes any free local port to be used. LocalPort is updated when fopen is issued.


To get a list of options you can use on a function, press the Tab key after entering a function on the MATLAB® command line. The list expands, and you can scroll to choose a property or value. For information about using this advanced tab completion feature, see Using Tab Completion for Functions.

Introduced before R2006a