socket()

This function creates an endpoint for communication. To establish communication, every process needs a socket at the end of the communication line. Also, the two communicating processes must have the same socket type and both should be in the same domain. Here is the syntax for creating a socket:

int socket(int domain, int type, int protocol);

Here, domain represents the communication domain in which a socket is to be created. Basically, the address family or protocol family is specified, which will be used in the communication.

A few of the popular address family are listed as follows:

You can replace the AF_ prefix in the preceding list with PF_ for protocol family.

On successful execution, the socket function returns a file descriptor that can be used to manage sockets.