SWRU368C May 2018 – January 2021 CC3100 , CC3100MOD , CC3200 , CC3200MOD
Similar to the previous TCP example, create a IPv4-based socket. However, change the second parameter to SL_SOCK_DGRAM, which indicates the socket will be used for a UDP connection.
SockID = sl_Socket(SL_AF_INET, SL_SOCK_DGRAM, 0);
Because UDP is a connectionless protocol, the client can start sending data to a specified target address without checking whether the target is alive or not.
#define IP_ADDR 0xc0a80164
#define PORT_NUM 5001
Addr.sin_family = SL_AF_INET;
Addr.sin_port = sl_Htons((UINT16)PORT_NUM);
Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR);
Status = sl_SendTo(SockID, uBuf.BsdBuf, BUF_SIZE, 0, (SlSockAddr_t *) &Addr, sizeof(SlSockAddrIn_t));
Finally, close the socket.
sl_Close(SockID);