BSD Sockets Interface Programmer's Guide
96 Chapter 4
Using Internet Datagram Sockets
Sending and Receiving Messages
Function result: Number of bytes actually sent, –1 in the event of an
error.
Example:
count = sendto(s,argv[2],strlen(argv[2]),0,servaddr,sizeof(struct
sockaddr_in));
The largest message size for this implementation is 32767 bytes.
You should not count on receiving error messages when using datagram
sockets. The protocol is unreliable, meaning that messages may or may
not reach their destination. However, if a message reaches its
destination, the contents of the message are guaranteed to be intact.
If you need reliable message transfer, you must build it into your
application programs or resend a message if the expected response does
not occur.
When to Send Data
The client or server process should send data after sockets are bound.
Refer to the send(2) man page for more information on sendto and
sendmsg.
Receiving Messages
Use recvfrom or recvmsg to receive messages. recvmsg allows the
read data to be scattered into buffers.
flags settings for optional flags 0 (no options are
currently supported)
to address of recipient socket pointer to the socket
address that message
should be sent to
tolen size of to length of address
structure that to points
to
Parameter Description of Contents INPUT Value