write
Prototype:
#include <unistd.h>
int write(int fd, char *buffer, int msg_len);
General Description: Write msg_len bytes to fd field descriptor from buffer. You may use a socket descriptor as well. However, it does not provide you with as much control as the send() system call.
Return Value: Number of bytes written. The byte count may be less that msg_len. If call does not succeed in writing all required bytes, you may use a loop for successive writes. If negative, the call stores the error detail in errno.
Parameters
fd File descriptor (may be a socket descriptor).
buffer The message to write.
msg_len The length of the message.
Possible Errors
EBADF fd is not a valid file descriptor or is not open for writing.
EINVAL fd is attached to an object which is unsuitable for writing.
EFAULT buf is outside your accessible address space.
EPIPE fd is connected to a pipe or socket whose reading end is closed. When this happens the writing process will receive a SIGPIPE signal; if it catches, blocks or ignores this the error EPIPE is returned.
EAGAIN Non-blocking I/O has been selected using O_NONBLOCK and there was no room in the pipe or socket connected to fd to write the data immediately.
EINTR The call was interrupted by a signal before any data was written.
ENOSPC The device containing the file referred to by fd has no room for the data.
EIO A low-level I/O error occurred while modifying the inode.
Examples
int sockfd;
int bytes, bytes_wrote=0;
/*--- Create socket, connect to server ---*/
while ( (bytes = write(sockfd, buffer, msg_len)) > 0 )
    if ( (bytes_wrote += bytes) >= msg_len )
        break;
if ( bytes < 0 )
    perror("write");