Write data to remote host over TCP/IP



write(t,data) sends the N-dimensional matrix of data from tcpclient object t connected to the remote host. The function waits until the specified values are written to the remote host.


collapse all

Create a TCP/IP object called t, connecting to a TCP/IP echo server, with Port of 7. This requires you to have an echotcpip server running on Port 7.

t = tcpclient('localhost', 7)
t = 

   tcpclient with properties:

          Address: 'local host'
             Port: 7
          Timeout: 10
   BytesAvailable: 0

The write function synchronously writes data to the remote host connected to the tcpclient object. First specify the data, then write the data. The function waits until the specified number of values is written to the remote host.

Assign 10 bytes of uint8 data to the variable data.

data = uint8(1:10)
data = 

  1    2    3    4    5    6    7    8    9    10

Check the data.

whos data
Name     Size     Bytes     Class     Attributes

data     1x10        10     uint8

Write data to the echo server.

write(t, data)

Check that the data was written using the BytesAvailable property.

ans = 


Read the data from the server.

ans = 

  1    2    3    4    5    6    7    8    9    10

Close the connection between the TCP/IP client object and the remote host by clearing the object.

clear t

Input Arguments

collapse all

Data to write to the remote host, specified as a 1xN matrix of numeric data.

Example: write(t, data)

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

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2014b