Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

61. Sockets: Advanced Topics > Socket-Specific I/O System Calls: recv() and sen...

Socket-Specific I/O System Calls: recv() and send()

The recv() and send() system calls perform I/O on connected sockets. They provide socket-specific functionality that is not available with the traditional read() and write() system calls.

#include <sys/socket.h>

ssize_t recv(int sockfd, void *buffer, size_t length, int flags);

Note

Returns number of bytes received, 0 on EOF, or -1 on error

ssize_t send(int sockfd, const void *buffer, size_t length, int flags);

Note

Returns number of bytes sent, or -1 on error

The return value and the first three arguments to recv() and send() are the same as for read() and write(). The last argument, flags, is a bit mask that modifies the behavior of the I/O operation. For recv(), the bits that may be ORed in flags include the following:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint