Socket Programming

Returning to our previous discussion on TCP data exchange, we have yet to explore the intricacies of connection initiation.

Figure 3.3a Three-way handshake.

Figure 3.3a Three-way handshake.

Socket programming plays a pivotal role in facilitating this process, allowing applications to establish connections for data transfer. Let's delve deeper into how socket programming fits into this mechanism.

TCP Socket API

The sequence of function calls for the client and a server participating in a TCP connection is presented in below.

Figure 4.1 TCP client-server.

Figure 4.1 TCP client-server.

<aside> <img src="/icons/map-pin_gray.svg" alt="/icons/map-pin_gray.svg" width="40px" /> For reference, the TCP client is the sender and TCP server is the receiver in Figure 3.3a.

</aside>

The Berkeley Socket System provides a set of low-level system primitives for network communication, as shown in Figure 4.1.

FIgure 4.2 Primitive used in Berkeley Socket:

FIgure 4.2 Primitive used in Berkeley Socket:

Refer to the page below for the full definition:

Berkeley Socket API

Recall that for TCP, both sender (client) and receiver (server) must synchronize.

Figure 4.5 Interaction among a client and a concurrent server.

Figure 4.5 Interaction among a client and a concurrent server.

The connected socket is closed by the parent since the child handles the client.

UDP Socket API

As we already learned, there are some fundamental differences between TCP and UDP sockets. UDP is a connection-less, unreliable, datagram protocol. Client applications using UDP can operate in two basic modes: