What is the difference between Socket and RPC?

roottraveller picture roottraveller · Sep 9, 2017 · Viewed 13.6k times · Source

What is the actual difference between Socket and RPC (Remote Procedure Call)?

As per my understanding both's working is based on Client–server model. Also which one should be used in which conditions?

PS: Confusion arise while reading Operating System Concepts by Galvin

Answer

selbie picture selbie · Sep 9, 2017

Short answer:

RPC is the protocol. The socket provides access to the transport to implement that protocol.

RPC is the service and protocol offered by the operating system to allow code to be triggered for running by a remote application. It has a defined protocol by which procedures or objects can be accessed by another device over a network. An implementation of RPC can be done over basically any network transport (e.g. TCP, UDP, cups with strings).

The socket is just a programming abstraction such that the application can send and receive data with another device through a particular network transport. You implement protocols (such as RPC) on top of a transport (such as TCP) with a socket.