1# OpenThread CLI - UDP Example 2 3The OpenThread UDP APIs may be invoked via the OpenThread CLI. 4 5## Quick Start 6 7### Form Network 8 9Form a network with at least two devices. 10 11### Node 1 12 13On node 1, open and bind the example UDP socket. 14 15```bash 16> udp open 17> udp bind :: 1234 18``` 19 20The `::` specifies the IPv6 Unspecified Address. 21 22### Node 2 23 24On node 2, open the example UDP socket and send a simple message. 25 26```bash 27> udp open 28> udp send fdde:ad00:beef:0:bb1:ebd6:ad10:f33 1234 hello 29``` 30 31### Result 32 33On node 1, you should see a print out similar to below: 34 35```bash 365 bytes from fdde:ad00:beef:0:dac3:6792:e2e:90d8 49153 hello 37``` 38 39## Command List 40 41- [help](#help) 42- [bind](#bind-netif-ip-port) 43- [close](#close) 44- [connect](#connect-ip-port) 45- [linksecurity](#linksecurity) 46- [open](#open) 47- [send](#send-ip-port-message) 48 49## Command Details 50 51### help 52 53List the UDP CLI commands. 54 55```bash 56> udp help 57help 58bind 59close 60connect 61open 62send 63Done 64``` 65 66### bind [netif] \<ip\> \<port\> 67 68Assigns a name (i.e. IPv6 address and port) to the example socket. 69 70- netif: the network interface to bind to. 71 - not specified: Thread network interface. 72 - `-u`: unspecified network interface. 73 - `-b`: Backbone network interface. 74- ip: the IPv6 address or the unspecified IPv6 address (`::`). 75- port: the UDP port 76 77```bash 78> udp bind :: 1234 79Done 80> udp bind -u :: 1234 81Done 82> udp bind -b :: 1234 83Done 84``` 85 86### close 87 88Closes the example socket. 89 90```bash 91> udp close 92Done 93``` 94 95### connect \<ip\> \<port\> 96 97Specifies the peer with which the socket is to be associated. 98 99- ip: the peer's IPv6 address. 100- port: the peer's UDP port. 101 102```bash 103> udp connect fdde:ad00:beef:0:bb1:ebd6:ad10:f33 1234 104Done 105``` 106 107### linksecurity 108 109Indicates whether the link security is enabled or disabled. 110 111```bash 112> udp linksecurity 113Enabled 114Done 115``` 116 117### linksecurity enable 118 119Enable link security. 120 121```bash 122> udp linksecurity enable 123Done 124``` 125 126### linksecurity disable 127 128Disable link security. 129 130```bash 131> udp linksecurity disable 132Done 133``` 134 135### open 136 137Opens the example socket. 138 139```bash 140> udp open 141Done 142``` 143 144### send \<ip\> \<port\> \<message\> 145 146Send a UDP message. 147 148- ip: the IPv6 destination address. 149- port: the UDP destination port. 150- message: the message to send. 151 152```bash 153> udp send fdde:ad00:beef:0:bb1:ebd6:ad10:f33 1234 hello 154Done 155``` 156 157### send \<ip\> \<port\> \<type\> \<value\> 158 159Send a few bytes over UDP. 160 161- ip: the IPv6 destination address. 162- port: the UDP destination port. 163- type: the type of the message: 164 - `-t`: text payload in the `value`, same as without specifying the type. 165 - `-s`: autogenerated payload with specified length indicated in the `value`. 166 - `-x`: binary data in hexadecimal representation in the `value`. 167 168```bash 169> udp send fdde:ad00:beef:0:bb1:ebd6:ad10:f33 1234 -t hello 170Done 171 172> udp send fdde:ad00:beef:0:bb1:ebd6:ad10:f33 1234 -x 68656c6c6f 173Done 174 175> udp send fdde:ad00:beef:0:bb1:ebd6:ad10:f33 1234 -s 800 176Done 177 178``` 179 180### send \<message\> 181 182Send a UDP message on a connected socket. 183 184- message: the message to send. 185 186```bash 187> udp send hello 188Done 189``` 190 191### send \<type\> \<value\> 192 193Send a few bytes over UDP. 194 195- type: the type of the message: 196 - `-t`: text payload in the `value`, same as without specifying the type. 197 - `-s`: autogenerated payload with specified length indicated in the `value`. 198 - `-x`: binary data in hexadecimal representation in the `value`. 199 200```bash 201> udp send -t hello 202Done 203 204> udp send -x 68656c6c6f 205Done 206 207> udp send -s 800 208Done 209``` 210