



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:
- create socket
- connect the socket to the address of the server
- send and receive data
For the server process socket creation is:
- create socket
- bind the socket to an address. For a server socket on the internet, this is a port on thew host machine listen for connections
- accept connections
- send and receive data
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.