Linux Sockets


In a Linux system a socket lies at either end of a communication channel between two processes. It uses a client/server model, where the client has to know the address of the server.

For the client process socket creation is:

For the server process socket creation is:

There are two items that must be defined at socket creation: address domain, and socket type. Two widely used domains are UNIX, in which two processes share a filesystem, and internet.

The address of a socket in the internet domain consists of an IP address and a port number.

Two common socket types are stream and datagram sockets. Stream sockets expect a stream of data and use TCP, while datagram sockets use UDP and have to read the entire message at once.