Main Content

write

Write data to UDP socket

    Description

    example

    write(u,data,destinationAddress,destinationPort)sends the vector of values indatato the specified IPdestinationAddressanddestinationPort, using the defaultdatatypeprecision ofuint8. 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 indatato the last useddestinationAddressanddestinationPort, using the defaultdatatypeprecision ofuint8. If you do not specifydestinationAddressanddestinationPortin a previous call towriteorwritelinefor the UDP socketu, this syntax throws an error.

    write(u,data,datatype)sends the vector of values indatausing the specifieddatatypeprecision, regardless of the actual type ofdata.

    write(u,data,datatype,destinationAddress,destinationPort)sends the vector of values indatausing the specifieddatatype,destinationAddress, anddestinationPort.

    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 theudpportobjectu, you can omit thedestinationAddressanddestinationPortarguments.

    Write a vector of single values.

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

    Input Arguments

    collapse all

    UDP socket, specified as audpportobject.

    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 ofdatais greater than theOutputDatagramSizeproperty of the UDP socket objectu, 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 useddestinationAddress. When you write to this address and port for the first time,destinationAddressis 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 thedestinationAddress, the function writes to the last useddestinationPort. When you write to this address and port for the first time,destinationPortis 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.datatypespecifies 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

    版本历史

    Introduced in R2020b

    See Also

    Functions