1. Overview

In this tutorial, we’ll explore two techniques used for network communication: socket and RPC.

We’ll also present the core differences between them.

2. Socket

Sockets are software structures that allow two processes to communicate over a network. It mainly responds to the need for functions that enable remote information exchange. Additionally, we use sockets in a centralized process of communication.

Socket combines an IP address and a port number. An IP address is a unique number that identifies a machine in the network. Additionally, a port number is a unique logical identifier for a process in the network. It helps to identify a process. In general, we use two major communication modes in socket programming: a non-connected UDP mode and a connected TCP mode.

A socket is an endpoint of a distributed communicating machine that uses sockets to implement the client-server model and solve different network applications. The distributed communication requires two sockets provided as two endpoints: one in the client and one in the server.

Thus, server sockets are generally responsible for receiving information from client sockets and responding to them based on the client-server application request. In contrast, there’s no possibility of finding an IP address and port number bound to different processes in a single machine in network communication. However, if a client knows the server’s IP address and port number, it’s possible to create a socket communication between two machines.

2.1. Working Procedure

As we already discussed, a socket address consists of an IP address and port number. The IP address helps to identify a specific system in a computer network. Additionally, the port number uniquely identifies a particular process in a system:


A socket can use either TCP or UPD for communication. Let’s look at a flowchart diagram of a client attempting server connection with TCP and UDP modes:


We can use UDP in socket connections when the client-server architecture is not necessary to follow. Therefore, before sending or receiving information, it is not essential to establish a connection between machines. An endpoint responds to clients without checking if both machines are eligible to exchange data or not.

In this case, we can’t guarantee that the data received contain the same packets sent from the client. It’s unreliable but allows large numbers of users to access endpoint servers.

In the case of a socket connected with TCP, we verify the integrity of all data by establishing a connection between two endpoints of sockets when sending and receiving data. Once connected, both machines test the communication port to ensure that data is capable of being transmitted successfully.

The client usually asks for the identity of an already owned server, to which the server responds with its own identity and requests the client’s identity. The data exchange between the client and server is ready to start by confirming the communication establishment.

2.2. Applications

Socket usage varies depending on the goal of the distributed application. An application that uses one of the provided modes (UDP/TCP) must consider what characteristics are available for each communication mode, including security, latency, or data integrity. However, we can use sockets in different domains where message exchange is needed.

Video conferencing applications like Zoom, Discord and Skype use socket connection with UDP since video streaming requires continuous data transmission. Therefore, it prevents the application from pausing to retransmit lost packets. Additionally, the majority of online games utilize sockets with UDP.

Voice Over IP (VoIP) applications such as Whatsapp and Viber require continuous voice/video transmission during voice/video calls. Therefore, these applications use socket connection with UDP. Additionally, one more important application is the Domain Name System (DNS).

On the other hand, the File Transfer Protocol (FTP) uses a socket connection with TCP. The consequence of data loss in file transferring is unacceptable. Hence, the FTP servers must use TCP protocol instead of UDP in order to check all packets and request a retransmission of packets if a missing packet is detected.

Other applications that utilize socket with TCP connection include the Hypertext Transfer Protocol (HTTP) and text communication via applications like Watsapp, Facebook, Instagram, and Google Chat.

3. RPC

The remote procedure call (RPC) is a communication protocol between processes that allows a machine to execute specific procedures using parameters from another machine across a network. It’s generally implemented in distributed systems, where different sites in different locations are physically separated. RPC is a high-level paradigm that considers the existence of transmission protocols during implementation.

3.1. Working Procedure

When a certain machine invokes a remote procedure from another machine in the system, the source call machine is held waiting for the results. In the destination call machine, the procedure parameters are extracted from the received messages and sent to the machine containing the required procedure. The procedure is executed using provided parameters. Additionally, we return the results to the machine that made that call. Let’s discuss the steps for invoking a call.

Initially, a client calls a procedure locally with given parameters using a client stub procedure. The client stub resides within the client’s own address space. Next, the stub encapsulates parameters as a message and sends it to the remote server via the transport layer.

The server receives the message using the server stub. As soon as the server receives the message, the server stub converts the message into parameters. Furthermore, the execution of the remote procedure in the server is maintained using converted results from the stub. The execution result is returned to the server stub to get converted into a message. Finally, we forward the message containing the results to the transport layer of the server.

The server’s transport layer transmits the message containing results to the client’s transport layer, which sends it back to the client stub. Furthermore, the client stub converts the message into the obtained results of the remote procedure.

3.2. Applications

Various RPC protocol usage can be found in remote calls to procedures, either locally or from different machines in distributed systems. Let’s discuss some applications that use RPC protocol.

Remote File Sharing (RFS) utilizes RPC in the distribution of databases. Remote access to databases improves system quality in terms of response time and reduces server congestion. Additionally, the Network File System (NFS) uses RPC protocol.

More applications that use RPC include the Windows Communication Foundation (WCF), an open-source programming interface in the .NET framework for building connected, service-oriented applications. Google Web Toolkit communicates to the server service using RPC.

4. Differences

The socket and RPC share the same goal of creating a channel of information flow with two different endpoint processes locally or distant that can communicate with each other using messages. Let’s discuss some core differences between them:

Rendered by QuickLaTeX.com

5. Conclusion

In this tutorial, we discussed two techniques that can create a channel of information flow in networking: socket and RPC. We presented the core differences between them.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.