Node:Sending Datagrams, Next:Receiving Datagrams, Up:Datagrams
The normal way of sending data on a datagram socket is by using the
sendto
function, declared in sys/socket.h
.
You can call connect
on a datagram socket, but this only
specifies a default destination for further data transmission on the
socket. When a socket has a default destination you can use
send
(see Sending Data) or even write
(see I/O Primitives) to send a packet there. You can cancel the default
destination by calling connect
using an address format of
AF_UNSPEC
in the addr argument. See Connecting, for
more information about the connect
function.
int sendto (int socket, void *buffer. size_t size, int flags, struct sockaddr *addr, socklen_t length) | Function |
The sendto function transmits the data in the buffer
through the socket socket to the destination address specified
by the addr and length arguments. The size argument
specifies the number of bytes to be transmitted.
The flags are interpreted the same way as for The return value and error conditions are also the same as for
It is also possible for one call to This function is defined as a cancellation point in multi-threaded programs, so one has to be prepared for this and make sure that allocated resources (like memory, files descriptors, semaphores or whatever) are freed even if the thread is canceled. |