Collaboration diagram for UDP Sockets:
UDP server and client applications typically use this order of API calls
Assigning a stream to a UDP socket is not supported. Applications must use NutUdpSendTo() and NutUdpReceiveFrom().
For historical reasons, Nut/Net buffers only the last incoming UDP datagram for a specific port by default. Any previously received datagram will be discarded, if it hasn't been passed to the application in the meantime. Most applications will run fine with this. But it will fail for example, if more than one response is expected on a previously broadcasted request. This problem can be solved by calling NutUdpSetSockOpt() to specify a receive buffer size.
#include <sys/socket.h> ... UDPSOCKET *sock; u_short udp_bufsiz = 1024; ... sock = NutUdpCreateSocket(20191); NutUdpSetSockOpt(sock, SO_RCVBUF, &udp_bufsiz, sizeof(udp_bufsiz));
Nut/Net supports connectionless UDP sockets only. A Berkley like bind call is not available.
Functions | |
UDPSOCKET * | NutUdpCreateSocket (u_short port) |
Create a UDP socket. | |
int | NutUdpSendTo (UDPSOCKET *sock, u_long addr, u_short port, void *data, u_short len) |
Send a UDP datagram. | |
int | NutUdpReceiveFrom (UDPSOCKET *sock, u_long *addr, u_short *port, void *data, u_short size, u_long timeout) |
Receive a UDP datagram. | |
int | NutUdpDestroySocket (UDPSOCKET *sock) |
Close UDP socket. | |
UDPSOCKET * | NutUdpFindSocket (u_short port) |
Find a matching socket. | |
int | NutUdpSetSockOpt (UDPSOCKET *sock, int optname, CONST void *optval, int optlen) |
Set value of a UDP socket option. | |
int | NutUdpGetSockOpt (UDPSOCKET *sock, int optname, void *optval, int optlen) |
Get a UDP socket option value. | |
Variables | |
UDPSOCKET * | udpSocketList |
|
Create a UDP socket.
|
|
Send a UDP datagram.
|
|
Receive a UDP datagram.
|
|
Close UDP socket. The memory occupied by the socket is immediately released after calling this function. The application must not use the socket after this call.
|
|
Find a matching socket. Loop through all sockets and find a matching one.
|
|
Set value of a UDP socket option. The following values can be set:
|
|
Get a UDP socket option value. The following values can be set:
|
|
Global linked list of all UDP sockets. |