(courtesy of Wikipedia)
In computer networking, the User Datagram Protocol (UDP) is one of the core communication protocols of the Internet protocol suite used to send messages (transported as datagrams in packets) to other hosts on an Internet Protocol (IP) network. Within an IP network, UDP does not require prior communication to set up communication channels or data paths.
UDP uses a simple connectionless communication model with a minimum of protocol mechanisms. UDP provides port numbers for addressing different functions at the source and destination of the datagram. It has no handshaking dialogues, and thus there is no guarantee of delivery, ordering, or duplicate protection.
UDP is suitable for purposes where error checking and correction are either not necessary or are performed in the application. Time-sensitive applications often use UDP because dropping packets is preferable to waiting for packets delayed due to retransmission, which may not be an option in a real-time system.
Applications can use datagram sockets to establish host-to-host communications. An application binds a socket to its endpoint of data transmission, which is a combination of an IP address and a port. In this way, UDP provides application multiplexing. A port is a software structure that is identified by the port number, a 16-bit integer value, allowing for port numbers between 0 and 65535. Port 0 is reserved but is a permissible source port value if the sending process does not expect messages in response.
For each block, there is a short description entry and a detailed block and component description. You can click on block pictures in the short description table to access the details and sample codes.
Sample codes on how to use the blocks have been provided. To try them out, all you have to do is open a browser session of the MicroBlocks IDE and drag and drop them onto the editor programming area. Then you can just click on them and see the results.
To test any of the sample codes below, just drag and drop them onto the MicroBlocks IDE.
WebSocket Library has two distinct types of block shapes:
oval: these are reporter blocks that return some kind of information back. The user would normally either assign these to a project variable or use it in a suitable input slot of other blocks.
rectangular: these are command blocks that perform a programmed function and do not return any information.
These library blocks will only work with microcontroller boards that are WIFI-capable; eg: ESP8266 and ESP32 family, PICO2040, etc.
Please make sure you use WIFI credentials specific to your network environment.
The ones used here are for example purposes and WILL NOT WORK.

This block is used to start the UDP protocol on the designated port.
Before starting the protocol, one needs to signon to the local Internet router to obtain an IP address.
This example demonstrates connecting to the local WIFI network and then staring the UDP protocol. Script loops waiting for a UDP message. If the message received is "LED", the user LED on the microcontroller is toggled and displayed.
Remember to substitute your own SSID and PASSWORD values for the WIFI connect block.
To send a UDP message to your own microcontroller, click on the provided UDP Send packet block after changing the IP address to your own IP address.


This block is used to stop the UDP protocol on the designated port.

This block will send a message to the IP and port designated. Make sure the port number matches the receivers port number.
IP address shown in the block is a BROADCAST IP address. Messages sent to this address will be received by all UDP clients active on the network. However, the broadcast version of the message WILL NOT BE RECEIVED by the original sender, even though it is also on the same network. To send a message to the SENDER, use its IP address in the block. Refer to the example in the UDP start block.

This block will return the UDP packet received from a remote UDP device. Refer to the example in the UDP start block.

This block will return the IP address of the remote device the last message was received from.

This block will return the UDP port number of the remote device the last message was received from.