Sockets and servers
A socket is one endpoint of a two-way communication link between two programs running on the network. Normally, a server (daemon) process runs on a specific computer and has a socket that is bound to a specific port number; the server just waits, listening to the socket for a client to make a connection request.
A program running on the client side knows the hostname of the machine on which the server is running and the port number on which the server is listening. To make a connection request, the client tries to rendezvous with the server on the server’s machine and port. The client also needs to identify itself with the server, so it binds to a local port number that it will use during this connection. This is usually assigned by the system.
If the client and server are on the same machine, this is referred to as localhost and always has an IP address of 127.0.0.1
assigned to it.
If everything goes well, the server accepts the connection and upon...