Is this code considerd easy enough!?
The receiving part
// Notify the user application about UDP socket events.
uint32_t udp_cb_func (int32_t socket, const NET_ADDR *addr, const uint8_t *buf, uint32_t len) {
// Data received
if ((buf[0] == 0x01) && (len == 2)) {
// Switch LEDs on and off
LED_out (buf[1]);
}
return (0);
}
The Transmitting part
// Send UDP data to destination client.
void send_udp_data (void) {
if (udp_sock >= 0) {
// IPv4 address: 192.168.0.1
NET_ADDR addr = { NET_ADDR_IP4, 2000, 192, 168, 1, 10 };
// IPv6 address: [fe80::1c30:6cff:fea2:455e]
// NET_ADDR addr = { NET_ADDR_IP6, 2000,
// 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x1c, 0x30, 0x6c, 0xff, 0xfe, 0xa2, 0x45, 0x5e };
uint8_t *sendbuf;
sendbuf = netUDP_GetBuffer (2);
sendbuf[0] = 'A';
sendbuf[1] = 'l';
sendbuf[2] = 'i';
sendbuf[3] = '\r';
sendbuf[4] = '\n';
netUDP_Send (udp_sock, &addr, sendbuf, 5);
}
}