Client/Server Model
TCP is a peer-to-peer, connection-oriented protocol. There are no master/slave relations. The applications, however, use a client/server model for communications.
A server is an application that offers a service to users; a client is a requester of a service. An application consists of both a server and a client part, which can run on the same or on different systems.
Users usually invoke the client part of the application, which builds a request for a particular service and sends it to the server part of the application using TCP/IP as a transport vehicle.
The server is a program that receives a request, performs the required service and sends back the results in a reply. A server can usually deal with multiple requests(multiple clients) at the same time.

Most servers wait for clients' requests at a well-known port so that their clients know to which TCP socket they must direct their requests. The client uses an arbitrary port for its communication. Clients that wish to communicate with a server that does not use a well-known port must have another mechanism for learning to which port they must address their requests.
This mechanism might employ a registration service such as Portmap, which uses a well-known port.

Application Programming Interfaces (APIs)
Application programming interfaces allow developers to write applications that can make use of TCP/IP services.
The Socket API
The socket interface is one of several application programming interfaces (APIs) to the communication protocols. Designed to be a generic communication programming interface, it was first introduced by the 4.2BSD UNIX system. Although it has not been standardized, it has become a de facto industry standard.
The socket interface is differentiated by the services that are provided to applications: stream sockets (connection-oriented), datagram sockets(connectionless), and raw sockets (direct access to lower layer protocols) services.

Winsock
A variation of the BSD sockets interface is provided by the Winsock interface developed by Microsoft and other vendors to support TCP/IP applications on Windows operating systems.

Basic interactions between a server & a client using socket calls:

        Server process                      Client process

**Initialize a socket.
FORMAT:
int sockfd = socket(int family, int type, int protocol)
Where:
– family stands for addressing family. It can take on values such as AF_UNIX, AF_INET, AF_NS, AF_OS2 and AF_IUCV. Its purpose is to specify the method of addressing used by the socket.
– type stands for the type of socket interface to be used. It can take on values such as SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, and SOCK_SEQPACKET.
– protocol can be UDP, TCP, IP or ICMP.
– sockfd is an integer (similar to a file descriptor) returned by the socket call.

**Bind ---(register) a socket to a port address.
FORMAT:
int bind(int sockfd, struct sockaddr *localaddr, int addrlen)
Where:
– sockfd is the same integer returned by the socket call.
– localaddr is the local address returned by the bind call.
Note that after the bind call, we now have values for the first three parameters inside our 5-tuple association:
{protocol, local-address, local-process, foreign-address, foreign-process}

**Indicate readiness to receive connections.
FORMAT:
int listen(int sockfd, int queue-size)
Where:
– sockfd is the same integer returned by the socket call.
– queue-size indicates the number of connection requests that can be queued by the system while the local process has not yet issued the accept call.

**Accept a connection.
FORMAT:
int accept(int sockfd, struct sockaddr *foreign-address, int addrlen)
Where:
– sockfd is the same integer returned by the socket call.
– foreign-address is the address of the foreign (client) process returned by the accept call.
Note that this accept call is issued by a server process rather than a client process. If there is a connection request waiting on the queue for this socket connection, accept takes the first request on the queue and creates another socket with the same properties as sockfd; otherwise, accept will block the caller process until a connection request arrives.

**Request connection to the server by a client
FORMAT:
int connect(int sockfd, struct sockaddr *foreign-address, int addrlen)
Where:
– sockfd is the same integer returned by the socket call.
– foreign-address is the address of the foreign (server) process returned by the connect call.
Note that this call is issued by a client process rather than a server process.

**Send and/or receive data.
The read( ), readv(sockfd, char *buffer int addrlen), recv( ), readfrom( ), send(sockfd, msg, len, flags) and write( ) calls can be used to receive and send data in an established socket association (or connection).
Note that these calls are similar to the standard read and write file I/O system calls.

**Close a socket.
FORMAT:
int close(int sockfd)
Where:
– sockfd is the same integer returned by the socket call.

Application layer protocols

DNS
Telnet
Ftp
Http
Tftp
Smtp
Snmp
X windows

Overall operation of an application using TCP/IP protocol suite

Let's assume that we are running an application layer program which involves networking via TCP/IP: For example, we are running an FTP application.