Establishing Connections

TCP connections are made between two endpoints. The endpoints may be on the same machine or on machines in two different parts of the world. Yet the principles behind each are the same.

When you create a socket it must assume one of two roles: 1) initiator, or 2) listener. Both roles are required. Without a listener socket no connection can be initiated. Similarly, without an initiator there’s no need for a listener.

In network programming the term commonly used for a socket that listens is a server and a socket that initiates a connection is a client. We’ll look at the lifecycle of each in turn.