|
|
HP 9000 Networking: BSD Sockets Interface Programmer's Guide > Chapter 4 Using Internet Datagram SocketsSending and Receiving Messages |
|
The sendto and recvfrom (or sendmsg and recvmsg) system calls are usually used to transmit and receive messages. Use sendto or sendmsg to send messages. sendmsg allows the send data to be gathered from several buffers. If you have declared a default address, you can use send , sendto, or sendmsg to send messages. If you use sendto or sendmsg in this special case, be sure you specify 0 as the address value or an error will occur. send is described in the "Sending Data" section in the "BSD Sockets: Using Internet Stream Sockets" chapter of this guide and in the send(2) man page. sendto and its parameters are described in the following table.
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. Use recvfrom or recvmsg to receive messages. recvmsg allows the read data to be scattered into buffers. recv can also be used if you do not need to know what socket sent the message. However, if you want to send a response to the message, you must know where it came from. Except for the extra information returned by recvfrom and recvmsg, the three calls are identical. recv is described in the "Receiving Data" section of the "BSD Sockets: Using Internet Stream Sockets" chapter in this guide and in the recv(2) man page. recvfrom and its parameters are described in the following table.
recvfrom blocks until there is a message to be received. No more than len bytes of data are returned. The entire message is read in one recvfrom, recvmsg, recv or read operation. If the message is too long for the allocated buffer, the excess data are discarded. Because only one message can be returned in a recvfrom call, if a second message is in the queue, it is not affected. Therefore, the best technique is to receive as much as possible on each call. The host does not wait for len bytes to be available; if less than len bytes are available, that number of bytes are returned. |
|