Main Content

write

Write data to UDP socket

Since R2020b

    Description

    write(u,data,destinationAddress,destinationPort) sends the vector of values in data to the specified IP destinationAddress and destinationPort, using the default datatype precision of uint8. The function waits until the requested number of values are written to the UDP socket, or until a timeout occurs.

    write(u,data) sends the vector of values in data to the last used destinationAddress and destinationPort, using the default datatype precision of uint8. If you do not specify destinationAddress and destinationPort in a previous call to write or writeline for the UDP socket u, this syntax throws an error.

    write(u,data,datatype) sends the vector of values in data using the specified datatype precision, regardless of the actual type of data.

    write(u,data,datatype,destinationAddress,destinationPort) sends the vector of values in data using the specified datatype, destinationAddress, and destinationPort.

    example

    Examples

    collapse all

    Write a vector of unsigned 8-bit values to a UDP socket.

    u = udpport;
    write(u, 1:5, "uint8", "192.1.5.15", 20);

    For future writes to the same destination address and port for the udpport object u, you can omit the destinationAddress and destinationPort arguments.

    Write a vector of single values.

    write(u,1:10,"single");

    Input Arguments

    collapse all

    UDP socket, specified as a udpport object.

    Example: u = udpport

    Data Types: udpport object

    Vector of values to write, specified as a row (1-by-N) or column (N-by-1) array of numeric data, string, or character vector. If the size of data is greater than the OutputDatagramSize property of the UDP socket object u, the function splits the data into multiple packets.

    Example: "Hello world"

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

    Destination address to write to, specified as a string or character vector. If you do not provide this value, the packet is sent to the last used destinationAddress. When you write to this address and port for the first time, destinationAddress is required.

    Example: "192.1.5.15"

    Data Types: char | string

    Destination port to write to, specified as a numeric value from 0 to 65535. If you do not provide this argument and the destinationAddress, the function writes to the last used destinationPort. When you write to this address and port for the first time, destinationPort is required.

    Example: 5110

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

    MATLAB data type for each value, specified as a string or character vector. datatype specifies the number of bits written for each value, and the interpretation of those bits as a MATLAB data type. Allowed values are "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "double", "single", "char", and "string".

    Example: "uint16"

    Data Types: char | string

    Version History

    Introduced in R2020b

    See Also

    Functions