In this tutorial, we’ll discuss two popular procedure calls: local and remote.
We’ll also explore the core differences between them.
2. Procedures in Programming
The procedure in modular programming is standalone code containing instructions. A procedure instructs the computer to execute a specific program or perform certain tasks.
A procedure differs from a function, a routine, or a method, which are used in various programming languages with the same fundamental role of allowing a programmer or a developer to call them multiple times within a program.
Procedure codes are created to improve code efficiency and reusability, which are lacking in classic linear programs. Additionally, maintaining solutions in complex processes lacking flexibility and refinement is extremely difficult. As a result, it leads to problematic development. However, by simply calling a procedure bound with different values, we can make a program execute differently using a separate set of parameters and data.
We can identify a procedure with an ID and a partition of code. Additionally, the structure of a procedure separates it from a larger code within a program. Generally, the procedures are custom-made within the program or in a code encapsulation known as object-oriented programming, which is popular and powerful in the developer community. However, in some cases, procedures are included within external libraries.
3. Introduction to Procedure Calls
In algorithmic languages, it’s common for procedures to have two statements: call and return. The procedure call transfers the control from the current process to another. We can also pass a list of parameters along with the procedure call. After successful execution, control returns to the initial procedure invoked, and the program continues its execution.
We can write a procedure call statement in a program by stating the procedure name, listing actual parameter names or values within parentheses, and adding a final semi-colon. When calling a procedure, we need to be very careful regarding the parameters. Furthermore, the parameters passed for the procedure call should match the original declared parameters. If case there’s a mismatch, the compiler throws an error.
Let’s look at an example of a procedure call:
procedure Show_Name(First_Name : in String, Last_Name : in String);
Here, we created a procedure in a program that contains two parameters: First_Name and Last_Name. Now let’s take a look at an example of a procedure call statement:
In a distributed architecture, the procedure call may follow additional protocols that allow it to invoke a procedure either remotely or locally:
4. Local Procedure Call
The Local Procedure Call (LPC), also known as Local Inter-Process Communication, is the feature for threads to synchronize and communicate when a memory is not shared. In LPC, we can exchange messages in synchronous and asynchronous communication modes via ports. The operating system provides built-in tools for data exchange and procedure calls for applications.
The LPC is widely used in Windows New Technology (NT) to communicate between internal subsystems. Furthermore, some applications of the LPC facilitate the separation of independent processes, while others facilitate the separation of decentralized computers. However, most of the applications that depend on LPC are based on local client-server architecture.
Additionally, in LPC, a client is an application that requests a task from another process or application. The server is the recipient of the call, which is also an application or process on the same computer. There’re numerous ways to apply LPC in an application project.
Let’s talk about an example. In the first case, let’s assume an application must communicate with other applications within different computers on a network, and it only depends on the local procedures. In such a case, we can utilize LPC.
Another example is when an application wants to communicate with different computers and operating systems. Furthermore, after the deployment of the application, users must communicate with certain applications. In this scenario, we can use LPC.
Now let’s explore some LPC mechanisms supported by the Windows operating system. The first function is file mapping which processes file contents and manages file reference sharing between processes. The second mechanism is the windows socket which allows processes to communicate with the network protocols (IP, TCP/UDP).
Additionally, in Windows operating system, the processes create mailslots. It acts as a server for processes to communicate with each other on a local computer. Finally, using the data copy method, applications cooperate in exchanging data using WM\_COPYDATA message form on a local computer.
5. Remote Procedure Call
When an RPC client calls a remote procedure, the control of the thread in the client application is set on the block and waits for the server’s response. The client waits a specific amount of time for a response. After the prespecified time, connection times out occur. Let’s look at the RPC procedure:
During the remote procedure call initiation, the client provides the ID of the procedure and arguments for the RPC server. After initiating a connection, the client sends the client stub to the server. The client may need to wait if the server is busy.
When a request arrives at the server, it calls a dispatch routine that handles the execution of the procedure with received arguments from the RPC client. As soon as the server finishes execution, the results are returned to the client, where it removes the block status and continues the instructions. In addition, windows RPC provides automatic data conversion support when the client and server run on different operating systems.
Now let’s talk about the RPC components. The RPC-based applications, especially the server side, must include four main elements: run-time libraries, endpoint mapper, MIDL compiler, and name service provider.
The remote procedures provide an interface using Interface Definition Language (IDL). The compiler receives the IDL interface to generate stubs that allow the local procedure to initiate remote calls. We can see the stubs as placeholder functions facilitating calls for run-time library functions.
Hence, providing an interface makes it transparent for decentralized applications. Thus, local clients can automatically invoke remote procedures the same way they would invoke a local procedure. Additionally, the MIDL compiler handles the data translation, network access, and calculation results.
RPC allows programs to invoke procedures remotely. Thus, RPC provides the LPC with the necessary features to easily call a function and work between processes on a single machine or multiple machines connected to a network. The remote procedure calls are generalized and can occur between different hosts or within the same host.
Processes that communicate using procedure calls use less memory. If the procedure exists locally, we generally use the LPC. However, we utilize the RPC if an application invokes a remote procedure to obtain the required calculation. Additionally, as we mentioned earlier, RPC can also be used to launch an LPC.
Now, let’s explore the core difference between the LPC and RPC:
In this tutorial, we discussed procedure calls in programming. We explored two variants of procedure calls: local and remote.
Finally, we presented the core differences between local and remote procedure calls.