|
|
With a connection established, data may begin to flow. There are several calls for sending and receiving data. With the peer entity at each end of a connection anchored, a user can send or receive a message without specifying the peer. Here, the normal read and write system calls are usable:
write(s, buf, sizeof(buf)); read(s, buf, sizeof(buf));In addition to read and write, the calls send and recv may be used:
send(s, buf, sizeof(buf), flags); recv(s, buf, sizeof(buf), flags);While send and recv are virtually identical to read and write, the extra flags argument is important. The flags, defined in sys/socket.h, may be specified as a non-zero value if one or more of the following is required:
Out-of-band data is specific to stream sockets. The option to have data sent without routing applied to the outgoing packets is currently used only by the routing table management process and is unlikely to be of interest to most users. However, the ability to preview data is of interest. When MSG_PEEK is specified with a recv call, any data present is returned to the user but treated as still unread. That is, the next read or recv call applied to the socket will return the data previously previewed.