Socket Connections
Initially, a socket is created in the unconnected state, meaning the socket is not associated with any foreign destination.
The connect subroutine binds a permanent destination to a socket, placing it in the connected state. An application program must call the connect subroutine to establish a connection before it can transfer data through a reliable stream socket. Sockets used with connectionless datagram services need not be connected before they are used, but connecting sockets makes it possible to transfer data without specifying the destination each time.
The semantics of the connect subroutine depend on the underlying protocols. An application program requiring reliable stream delivery service in the Internet family should select the Transmission Control Protocol (TCP). In such cases, the connect subroutine builds a TCP connection with the destination and returns an error if it cannot. In the case of connectionless services, the connect subroutine does nothing more than store the destination address locally. Similarly, application programs requiring connection-oriented datagram service in the operating system Network Device Driver (NDD) family should select the Asynchronous Transfer Mode (ATM) protocol. Connection in the ATM protocol establishes a permanent virtual circuit (PVC) or switched virtual circuit (SVC). For PVCs, the local station is set up, and there is no network activity. For SVCs, the virtual circuit is set up end-to-end in the network with the remote station.
- The server, when willing to offer its advertised services, binds a socket to a well-known address associated with the service, and then passively listens on its socket. It is then possible for an unrelated process to rendezvous with the server.
- The server process socket is marked to indicate incoming connections are to be accepted on it.
- The client requests services from the server by initiating a connection to the server's socket. The client process uses a connect subroutine to initiate a socket connection.
- If the client process' socket is unbound at the time of the connect call, the system automatically selects and binds a name to the socket if necessary. This is the usual way that local addresses are bound to a socket.
- The system returns an error if the connection fails (any name automatically bound by the system, however, remains). Otherwise, the socket is associated with the server and data transfer can begin.