Before going into detail we want to clarify two things.
First, When we say programs in the context of Network Programming we really mean processes. A process is a program that has been loaded into the memory and currently running(executing). It has its own memory space and system resources. A process is regarded as a unit of execution in the operating system context. A process is a basic entity to which OS allocates resources.
Second, Networking Programming is often called “Socket Programming“. You will hear this a lot. The terms are often used interchangeably.
What Does Sending And Receiving Data Over A Network Mean?
Assume you have written two programs(processes). One program serves as the Server. The other program serves as the Client. For simplicity, let us assume that both the Server and the Client are running on the same machine. The perplexing question now is, how do they communicate with one another? As we discussed in the previous tutorial, each process’s memory is sandboxed so that it cannot be accessed by another process. Even if the two programs are on the same machine, they cannot communicate directly with each other because of sandboxing. And if they are on different machines, the communication between the programs becomes even more complicated!
Let us give you a real life example. Assume the server(or server program) is a Time Server. A Time Service is a network service that provides precise time to other computers on a network. The client program requests the current time from the Time Server. Try to answer the following questions. It’s okay if you do not get them right. We just want you to guess.
- How does the Client send the current-time request to the Server?
- How does the request get from the Client to the Server?
- How does the message(request) reach the server?
- What method does the server use to send the response?
As previously stated, most applications are made up of pairs of communicating processes, with the two processes in each pair sending messages to one another. Any message passed from one process to another must traverse the underlying network.
Note: Don't be concerned about the client and server programs. We've included them to give you a visual representation. Later in this tutorial, we'll show you how these programs work. But keep in mind that both programs are in the Application Layer.
The above diagram shows that the client program’s request(message) must first go to the Presentation Layer from the Application Layer. The Presentation Layer is the layer directly below the Application Layer. A Session Layer(directly below the Presentation Layer) and a Transport Layer(directly below the Session Layer) are also present. In addition, there is a Network Layer, a Data Link Layer, and a Physical Layer in a subsequent order as depicted in the above diagram. The request must traverse these layers too. Some interesting things happen when the request reaches the Physical Layer. The message is converted to a signal in the Physical Layer. Then the signal leaves the Client host(machine). The signal eventually reaches the Physical Layer of the Server host (either through wire or wirelessly). The signal is then converted back to data, and the message is sent to the Application Layer. This time the message traverses upward.
If you observe the above diagram carefully, you will notice that there is a Transport Layer visible there. As the name suggests, it is the Transport Layer that is responsible for delivering the message to the destination. As a consequence, we have to figure out some way so that we can send our data from the Application Layer to the Transport Layer(in the same machine). Then it is Transport Layer’s responsibility to ensure that the message reaches its destination. We should not and need not worry about how Transport Layer makes this “transporting” happen. We are, after all, Application Developers. We should spend the majority of our time writing business logic for our program rather than figuring out how to transport messages. We should delegate these responsibilities to the people in charge of the Transport Layer. We need some kind of abstraction so that we may hide the underlying complexity of a system and present a simplified, higher-level view of it.
And this abstraction is known as a Socket(socket will be discussed later in this course) in our networking context. A process sends and receives messages from the network via a software interface known as a Socket. In networking, an interface refers to a point of interaction or connection between two or more devices or systems. An interface can refer to both hardware and software components. Do not worry if you do not understand what an interface is. We will discuss it in a minute.
What Is An Interface?
According to wikipedia,
If this definition seems hazy, do not worry. Allow us to explain interface to you.
In our Networking fundamentals course we told you that network interface is the point at which a computer connects to a private or public network. A network interface is commonly referred to as a Network Interface Card (NIC) which is a physical networking component and it allows us to connect to a network. But an interface does not always have to be a physical component. Instead a network interface can be implemented in software. For example, the loopback interface (127.0.0.1 for IPv4 and::1 for IPv6) is a piece of software that simulates a network interface rather than a physical device. In test environments, the loopback interface is commonly used.
In order to communication happen between different systems and devices an interface is needed. Think of an interface as a bridge between different protocols, devices and technologies. The interface enables them to understand and communicate with each other.
The rules and protocols, that are required to be followed for communication to take place, are defined by the interface. The interface also defines the format of the data that will be transmitted, the error detection and correction methods or mechanisms, and finally the flow control mechanisms.
Interface also provides a way for applications to access the network services, such as file transfer, email, and voice communication, without needing to know the low-level networking details and technologies.
Additionally, interfaces help to abstract the complexity of the underlying hardware and software, making it easier for developers to create new applications and services, and allowing for greater flexibility and scalability in networks.
An Interface Analogy
Though the heading says an interface analogy, we will be giving more than one. This variety of examples is provided because we believe it is important for young designers to understand that there is great (and terrible) interface design outside of software user interface design.
Suppose there are two different systems. Each system has its own set of properties and functions. They have no idea that the other system exists. What happens when these two different systems want to exchange information and collaborate to achieve a common goal? An interface comes into the picture.
Think of an interface as a shared boundary between the systems. It is the point of contact between the systems. The systems exchange messages with each other through the “interface”. An interface can be regarded as a medium that allows one thing(object, system, component, etc. ) to interact with another.
To fully grasp the concept of interface consider the following scenario. In a park two people are enjoying the view. After a while one of them tries to interact with the other. They need some kind of medium so that they can interact with each other, don’t they? Suppose that they both speak the same language(English in this scenario). So they can have conversations(exchange messages) with each other. In this example, language is an example of an interface.
Again, suppose that they do not speak the same language. One of them speaks German and the other speaks only Japanese. Now to exchange messages they need a translator. In this scenario, the translator is the interface for someone to interact with another person who do not speak the same language. The translator is the medium through which they interact.
The term “interface” is often used to refer to the “user interface”. In this context, the “user interface” is the medium through which a user interacts with a computer, software or hardware device. It may be graphical(GUI) or simple command-line(CLI) based. The purpose of an user interface is to provide a way for the user so that the user can access and control the functions and features of the device and the software.
Consider the analogy of a messenger user interface.
The user interface of the Messenger App allows users to send and receive messages, make audio and video calls, and access other features. It provides these functionalities and other features in such a way that is easy as well as intuitive to use. For example, to see the full message Jean sent you, you click on Jean and the Messenger App shows you the full message.
A process sends and receives messages from the network via a software interface known as a Socket.
Sockets provide a way for processes to communicate with each other, regardless of their location. They allow for the separation of the application logic from the low-level details of the network, such as the protocol and the physical medium. This abstraction allows for more flexibility, as it allows the application to be easily ported to different networks and protocols.
In the next tutorial, we will be talking about Sockets and how they are used to send and receive messages from the network.