Main Content

writeline

Write line of ASCII data to UDP socket

Since R2020b

    Description

    writeline(u,data,destinationAddress,destinationPort) writes the ASCII data data, followed by the terminator, to the specified IP destinationAddress and destinationPort. u must be a byte-type udpport object. The function waits until the data and terminator are written to the UDP socket, or until a timeout occurs.

    writeline(u,data) writes the ASCII data to the last used destinationAddress and destinationPort. 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.

    example

    Examples

    collapse all

    Write start and stop commands to a UDP socket.

    Create a UDP socket and write an ASCII "START" string to a specified address and port.

    u = udpport;
    writeline(u,"START","192.1.5.15",20)

    The function appends the default terminator to the written string.

    Write an ASCII "STOP" string to the same address and port.

    writeline(u,"STOP")

    Input Arguments

    collapse all

    UDP socket, specified as a udpport object.

    Example: u = udpport

    Data Types: udpport object

    String to write to udpport socket, specified as a string or character vector. The terminator is appended. 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: char | string

    Destination address to write to, specified as a string or character vector. If you do not provide this argument, the function writes 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

    Version History

    Introduced in R2020b

    See Also

    Functions