The OpenThread UDP APIs may be invoked via the OpenThread CLI.
Form a network with at least two devices.
On node 1, open and bind the example UDP socket.
> udp open
> udp bind :: 1234The :: specifies the IPv6 Unspecified Address.
On node 2, open the example UDP socket and send a simple message.
> udp open
> udp send fdde:ad00:beef:0:bb1:ebd6:ad10:f33 1234 helloOn node 1, you should see a print out similar to below:
5 bytes from fdde:ad00:beef:0:dac3:6792:e2e:90d8 49153 helloList the UDP CLI commands.
> udp help
help
bind
close
connect
open
send
DoneAssigns a name (i.e. IPv6 address and port) to the example socket.
- netif: the network interface to bind to.
- not specified: Thread stack network interface.
-u: unspecified network interface.-b: Backbone network interface.-h: Host Thread network interface.
- ip: the unicast IPv6 address or the unspecified IPv6 address (
::). - port: the UDP port
Note: the netif parameter values (-u, -b, -h) are only valid if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE is set.
> udp bind :: 1234
Done
> udp bind -u :: 1234
Done
> udp bind -b :: 1234
Done
> udp bind -h :: 1234
DoneNote: to receive datagrams sent to a multicast IPv6 address, the unspecified IPv6 address must be used. Using a multicast address for the <ip> argument is not supported. Also, the node must subscribe to the multicast group using
ipmaddr addbefore it can receive UDP multicast.
Closes the example socket.
> udp close
DoneSpecifies the peer with which the socket is to be associated.
- ip: the peer's IP address.
- port: the peer's UDP port.
> udp connect fdde:ad00:beef:0:bb1:ebd6:ad10:f33 1234
DoneThe address can be an IPv4 address, which will be synthesized to an IPv6 address using the preferred NAT64 prefix from the network data.
Note: The command will return
InvalidStatewhen the preferred NAT64 prefix is unavailable.
> udp connect 172.17.0.1 1234
Connecting to synthesized IPv6 address: fdde:ad00:beef:2:0:0:ac11:1
DoneIndicates whether the link security is enabled or disabled.
> udp linksecurity
Enabled
DoneEnable link security.
> udp linksecurity enable
DoneDisable link security.
> udp linksecurity disable
DoneOpens the example socket.
> udp open
DoneSend a UDP message.
- ip: the destination address.
- port: the UDP destination port.
- message: the message to send.
> udp send fdde:ad00:beef:0:bb1:ebd6:ad10:f33 1234 hello
DoneThe address can be an IPv4 address, which will be synthesized to an IPv6 address using the preferred NAT64 prefix from the network data.
Note: The command will return
InvalidStatewhen the preferred NAT64 prefix is unavailable.
> udp send 172.17.0.1 1234 hello
Sending to synthesized IPv6 address: fdde:ad00:beef:2:0:0:ac11:1
DoneSend a few bytes over UDP.
- ip: the IPv6 destination address.
- port: the UDP destination port.
- type: the type of the message:
-t: text payload in thevalue, same as without specifying the type.-s: autogenerated payload with specified length indicated in thevalue.-x: binary data in hexadecimal representation in thevalue.
> udp send fdde:ad00:beef:0:bb1:ebd6:ad10:f33 1234 -t hello
Done
> udp send fdde:ad00:beef:0:bb1:ebd6:ad10:f33 1234 -x 68656c6c6f
Done
> udp send fdde:ad00:beef:0:bb1:ebd6:ad10:f33 1234 -s 800
Done
Send a UDP message on a connected socket.
- message: the message to send.
> udp send hello
DoneSend a few bytes over UDP.
- type: the type of the message:
-t: text payload in thevalue, same as without specifying the type.-s: autogenerated payload with specified length indicated in thevalue.-x: binary data in hexadecimal representation in thevalue.
> udp send -t hello
Done
> udp send -x 68656c6c6f
Done
> udp send -s 800
Done