The following sections will explain, in detail, the different socket APIs.
Beginning with APIs
The socket() API
All POSIX socket programming starts with the creation of a socket file descriptor using the socket() API, which takes the following form:
int socket(int domain, int type, int protocol);
The domain defines the address type used when creating the socket. In most cases, this would be AF_INET for IPv4 or AF_INET6 for IPv6. In the case of our examples in this chapter, we will use AF_INET. The type field usually takes on SOCK_STREAM for a TCP connection or SOCK_DGRAM for a UDP connection, both of which will be demonstrated in this chapter. Finally, the protocol field in this API will be set to 0 in all of our examples...