 |
» |
|
|
|
After the connect and accept calls are successfully executed,
the connection is established and data can be sent and received between
the two socket endpoints. Because the stream socket descriptors
correspond to HP-UX file descriptors, you can use the read
and write calls (in addition to
recv
and send) to pass data through
a socket-terminated channel. If you are considering the use of the read
and write system calls instead
of the send and recv
calls described below, you should consider the following: If you use read
and write instead of send
and recv, you can use a socket
for stdin or stdout. If you use read
and write
instead of send
and recv, you cannot use the options
specified with the send or recv
flags parameter.
See the table that lists other system calls in chapter 8,
for more information on which of these system calls are best for
your application. Sending Data |  |
send and its parameters are described in the following
table. - Include files:
#include <sys/types.h> #include <sys/socket.h>
|
- System call:
count = send(s,msg,len,flags) int s; char *msg; int len, flags;
|
- Function result:
number of bytes actually sent, -1 if failure
occurs.
Example: count = send (s, buf, 10, 0);
|
send blocks until the specified
number of bytes have been queued to be sent, unless you are using
nonblocking I/O. The server or client process should send data after the connection
is established. Refer to the send(2)
man page for more information on send. Receiving Data |  |
recv and its parameters are described in the following table. - Include files:
#include <sys/types.h> #include <sys/socket.h>
|
- System call:
count = recv(s,buf,len,flags) int s; char *buf; int len, flags;
|
- Function result:
number of bytes actually received, -1 if
failure occurs.
Example: count = recv(s, buf, 10, 0);
|
recv blocks until there is
at least 1 byte of data to be received, unless you are using nonblocking
I/O. The host does not wait for len
bytes to be available; if less than len
bytes are available, that number of bytes are received. No more than len bytes of
data are received. If there are more than len
bytes of data on the socket, the remaining bytes are received on
the next recv. Flag Options |  |
The flag options
are: MSG_OOB for out of band data. MSG_PEEK for a nondestructive read .
Use the MSG_OOB option if you want to receive out of band
data. Refer to the "Sending and Receiving Out of Band Data"
section of chapter 3, "Advanced
Topics for Stream Sockets," for more information. Use the MSG_PEEK option to preview incoming data. If this option is set
on a recv, any data returned remains
in the socket buffer as though it had not been read yet. The next
recv returns the same data. The server or client process should receive data after connection
is established. Refer to the recv(2)
man page for more information on recv.
|