Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

write

Write data to remote host over TCP/IP

Syntax

write(t,data)

Description

example

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.

Examples

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.

t.BytesAvailable
ans = 

    10

Read the data from the server.

read(t)
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

Introduced in R2014b

Was this topic helpful?