gtpc1m3bTransmission Control Protocol/Internet Protocol

Function Calls Used in a Sample TCP Session

In a TCP connected stream socket session, the roles of server and client are more clearly defined than in a datagram socket session. Once you make the connection, the connection exists until you close the socket. A connected socket, as used in TCP protocol, sends data to and receives data from only one server because it has a dedicated destination. The following steps correspond to the numbers in Figure 23:

  1. The server is started first by issuing a socket call to create socket s. The client then issues a socket call and creates its own socket s. A socket is initially created in the unconnected state, which means that the socket is not associated with any remote destination.
  2. The server issues a bind call to a local address to be positioned for a subsequent connection.

    The client can issue an optional bind call to a local address.

  3. Using the listen function, the server waits for a connection from the client.
  4. The connect call places the socket in the connected state. The client must issue the connect call before being able to transfer data through a reliable stream socket.
  5. The server issues an accept call to accept an incoming connection. To allow the server socket s to remain available for the next client connection, the accept call creates a new socket ns, which is dedicated to the client.
  6. The read and write calls between the client and server continue until all the data is transferred.
  7. The client closes socket s and the server closes the related socket, socket ns.
  8. The server can continue to accept other connections on the original socket s or close it by using the close function.

Figure 23. Sample Socket Session Using TCP Protocol