{"id":2553,"date":"2025-06-07T11:43:17","date_gmt":"2025-06-07T11:43:17","guid":{"rendered":"https:\/\/diznr.com\/?p=2553"},"modified":"2025-06-07T11:43:17","modified_gmt":"2025-06-07T11:43:17","slug":"remote-procedure-call-rpc-define-procedure-java-rpc-remote-procedure-call-in-system-distributed","status":"publish","type":"post","link":"https:\/\/www.reilsolar.com\/pdf\/remote-procedure-call-rpc-define-procedure-java-rpc-remote-procedure-call-in-system-distributed\/","title":{"rendered":"Remote Procedure Call-RPC define procedure java rpc-Remote Procedure Call in Distributed System"},"content":{"rendered":"<p>Remote Procedure Call-RPC define procedure java rpc-Remote Procedure Call in Distributed System.<\/p>\n<p>[fvplayer id=&#8221;68&#8243;]<\/p>\n<h3 class=\"\" data-start=\"0\" data-end=\"67\"><strong data-start=\"4\" data-end=\"65\">Remote Procedure Call (RPC) in Java &amp; Distributed Systems<\/strong><\/h3>\n<h4 class=\"\" data-start=\"69\" data-end=\"116\"><strong data-start=\"74\" data-end=\"114\">What is Remote Procedure Call (RPC)?<\/strong><\/h4>\n<p class=\"\" data-start=\"117\" data-end=\"382\">Remote Procedure Call (RPC) is a protocol that allows a <strong data-start=\"173\" data-end=\"237\">program to execute a procedure (function) on a remote server<\/strong> as if it were a local function call. It is widely used in <strong data-start=\"296\" data-end=\"319\">distributed systems<\/strong> for communication between different machines over a network.<\/p>\n<h3 data-start=\"389\" data-end=\"419\"><strong data-start=\"392\" data-end=\"417\">1. How Does RPC Work?<\/strong><\/h3>\n<p class=\"\" data-start=\"420\" data-end=\"789\">RPC follows these steps:<br data-start=\"444\" data-end=\"447\" \/><strong data-start=\"451\" data-end=\"477\">Client makes a request<\/strong> to invoke a function on a remote server.<br data-start=\"518\" data-end=\"521\" \/>\u00a0The request is <strong data-start=\"540\" data-end=\"576\">converted into a network message<\/strong> and sent.<br data-start=\"586\" data-end=\"589\" \/>\u00a0The <strong data-start=\"597\" data-end=\"616\">server receives<\/strong> the request and executes the function.<br data-start=\"655\" data-end=\"658\" \/>\u00a0The <strong data-start=\"666\" data-end=\"689\">result is sent back<\/strong> to the client over the network.<br data-start=\"721\" data-end=\"724\" \/>\u00a0The client receives the result and <strong data-start=\"763\" data-end=\"786\">continues execution<\/strong>.<\/p>\n<p class=\"\" data-start=\"791\" data-end=\"1167\"><strong data-start=\"794\" data-end=\"820\">Key Components of RPC:<\/strong><br data-start=\"820\" data-end=\"823\" \/><strong data-start=\"825\" data-end=\"845\">Client &amp; Server:<\/strong> The client calls the remote function, and the server executes it.<br data-start=\"911\" data-end=\"914\" \/><strong data-start=\"916\" data-end=\"925\">Stub:<\/strong> Acts as an interface between the local and remote procedure calls.<br data-start=\"992\" data-end=\"995\" \/><strong data-start=\"997\" data-end=\"1029\">Marshalling &amp; Unmarshalling:<\/strong> Converts data into a format suitable for transmission.<br data-start=\"1084\" data-end=\"1087\" \/><strong data-start=\"1089\" data-end=\"1112\">Transport Protocol:<\/strong> RPC can use <strong data-start=\"1125\" data-end=\"1146\">TCP, UDP, or HTTP<\/strong> for communication.<\/p>\n<h3 data-start=\"1174\" data-end=\"1248\"><strong data-start=\"1177\" data-end=\"1246\">2. RPC in Java \u2013 Implementing Java RMI (Remote Method Invocation)<\/strong><\/h3>\n<p class=\"\" data-start=\"1249\" data-end=\"1410\">In Java, RPC is implemented using <strong data-start=\"1283\" data-end=\"1322\">Java RMI (Remote Method Invocation)<\/strong>. Java RMI allows an object to call methods of a remote object running on another JVM.<\/p>\n<h3 class=\"\" data-start=\"1412\" data-end=\"1451\"><strong data-start=\"1416\" data-end=\"1449\">Step-by-Step Java RMI Example<\/strong><\/h3>\n<p class=\"\" data-start=\"1453\" data-end=\"1495\"><strong data-start=\"1456\" data-end=\"1493\">Step 1: Define a Remote Interface<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-java\"><code class=\"!whitespace-pre language-java\"><span class=\"hljs-keyword\">import<\/span> java.rmi.Remote;<br \/>\n<span class=\"hljs-keyword\">import<\/span> java.rmi.RemoteException;<\/code><\/code><span class=\"hljs-comment\">\/\/ Remote Interface<\/span><br \/>\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">interface<\/span> <span class=\"hljs-title class_\">Hello<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title class_\">Remote<\/span> {<br \/>\nString <span class=\"hljs-title function_\">sayHello<\/span><span class=\"hljs-params\">()<\/span> <span class=\"hljs-keyword\">throws<\/span> RemoteException;<br \/>\n}<\/div>\n<\/div>\n<p class=\"\" data-start=\"1675\" data-end=\"1722\"><strong data-start=\"1678\" data-end=\"1720\">Step 2: Implement the Remote Interface<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-java\"><code class=\"!whitespace-pre language-java\"><span class=\"hljs-keyword\">import<\/span> java.rmi.server.UnicastRemoteObject;<br \/>\n<span class=\"hljs-keyword\">import<\/span> java.rmi.RemoteException;<\/code><\/code><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">HelloImpl<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title class_\">UnicastRemoteObject<\/span> <span class=\"hljs-keyword\">implements<\/span> <span class=\"hljs-title class_\">Hello<\/span> {<br \/>\n<span class=\"hljs-keyword\">protected<\/span> <span class=\"hljs-title function_\">HelloImpl<\/span><span class=\"hljs-params\">()<\/span> <span class=\"hljs-keyword\">throws<\/span> RemoteException {<br \/>\n<span class=\"hljs-built_in\">super<\/span>();<br \/>\n}<code class=\"!whitespace-pre language-java\"><code class=\"!whitespace-pre language-java\"><\/code><\/code><span class=\"hljs-keyword\">public<\/span> String <span class=\"hljs-title function_\">sayHello<\/span><span class=\"hljs-params\">()<\/span> <span class=\"hljs-keyword\">throws<\/span> RemoteException {<br \/>\n<span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">&#8220;Hello from Remote Server!&#8221;<\/span>;<br \/>\n}<br \/>\n}<\/div>\n<\/div>\n<p class=\"\" data-start=\"2065\" data-end=\"2113\"><strong data-start=\"2068\" data-end=\"2111\">Step 3: Create and Start the RMI Server<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-java\"><code class=\"!whitespace-pre language-java\"><span class=\"hljs-keyword\">import<\/span> java.rmi.registry.LocateRegistry;<br \/>\n<span class=\"hljs-keyword\">import<\/span> java.rmi.registry.Registry;<\/code><\/code><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">Server<\/span> {<br \/>\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title function_\">main<\/span><span class=\"hljs-params\">(String[] args)<\/span> {<br \/>\n<span class=\"hljs-keyword\">try<\/span> {<br \/>\n<span class=\"hljs-type\">HelloImpl<\/span> <span class=\"hljs-variable\">obj<\/span> <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">HelloImpl<\/span>();<br \/>\n<span class=\"hljs-type\">Registry<\/span> <span class=\"hljs-variable\">registry<\/span> <span class=\"hljs-operator\">=<\/span> LocateRegistry.createRegistry(<span class=\"hljs-number\">1099<\/span>);<br \/>\nregistry.rebind(<span class=\"hljs-string\">&#8220;Hello&#8221;<\/span>, obj);<br \/>\nSystem.out.println(<span class=\"hljs-string\">&#8220;Server is running&#8230;&#8221;<\/span>);<br \/>\n} <span class=\"hljs-keyword\">catch<\/span> (Exception e) {<br \/>\ne.printStackTrace();<br \/>\n}<br \/>\n}<br \/>\n}<\/div>\n<\/div>\n<p class=\"\" data-start=\"2581\" data-end=\"2618\"><strong data-start=\"2584\" data-end=\"2616\">Step 4: Create an RMI Client<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-java\"><code class=\"!whitespace-pre language-java\"><span class=\"hljs-keyword\">import<\/span> java.rmi.registry.LocateRegistry;<br \/>\n<span class=\"hljs-keyword\">import<\/span> java.rmi.registry.Registry;<\/code><\/code><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">Client<\/span> {<br \/>\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title function_\">main<\/span><span class=\"hljs-params\">(String[] args)<\/span> {<br \/>\n<span class=\"hljs-keyword\">try<\/span> {<br \/>\n<span class=\"hljs-type\">Registry<\/span> <span class=\"hljs-variable\">registry<\/span> <span class=\"hljs-operator\">=<\/span> LocateRegistry.getRegistry(<span class=\"hljs-string\">&#8220;localhost&#8221;<\/span>, <span class=\"hljs-number\">1099<\/span>);<br \/>\n<span class=\"hljs-type\">Hello<\/span> <span class=\"hljs-variable\">stub<\/span> <span class=\"hljs-operator\">=<\/span> (Hello) registry.lookup(<span class=\"hljs-string\">&#8220;Hello&#8221;<\/span>);<br \/>\nSystem.out.println(stub.sayHello());<br \/>\n} <span class=\"hljs-keyword\">catch<\/span> (Exception e) {<br \/>\ne.printStackTrace();<br \/>\n}<br \/>\n}<br \/>\n}<\/div>\n<\/div>\n<h3 data-start=\"3065\" data-end=\"3117\"><strong data-start=\"3068\" data-end=\"3115\">3. Advantages of RPC in Distributed Systems<\/strong><\/h3>\n<p class=\"\" data-start=\"3118\" data-end=\"3415\"><strong data-start=\"3120\" data-end=\"3135\">Simplicity:<\/strong> Makes remote method calls look like local function calls.<br data-start=\"3193\" data-end=\"3196\" \/><strong data-start=\"3198\" data-end=\"3224\">Platform Independence:<\/strong> Works across different operating systems.<br data-start=\"3266\" data-end=\"3269\" \/><strong data-start=\"3271\" data-end=\"3287\">Abstraction:<\/strong> Hides the complexity of network communication.<br data-start=\"3334\" data-end=\"3337\" \/><strong data-start=\"3339\" data-end=\"3355\">Flexibility:<\/strong> Supports different transport protocols (TCP, HTTP, etc.).<\/p>\n<h3 data-start=\"3422\" data-end=\"3453\"><strong data-start=\"3425\" data-end=\"3451\">4. Alternatives to RPC<\/strong><\/h3>\n<p class=\"\" data-start=\"3454\" data-end=\"3691\"><strong data-start=\"3457\" data-end=\"3479\">gRPC (Google RPC):<\/strong> Uses Protocol Buffers (protobuf) for efficient communication.<br data-start=\"3541\" data-end=\"3544\" \/><strong data-start=\"3547\" data-end=\"3561\">REST APIs:<\/strong> HTTP-based communication for distributed services.<br data-start=\"3612\" data-end=\"3615\" \/><strong data-start=\"3618\" data-end=\"3659\">SOAP (Simple Object Access Protocol):<\/strong> XML-based messaging protocol.<\/p>\n<h3 class=\"\" data-start=\"3698\" data-end=\"3721\"><strong data-start=\"3702\" data-end=\"3719\">\u00a0Conclusion<\/strong><\/h3>\n<p class=\"\" data-start=\"3722\" data-end=\"4053\"><strong data-start=\"3722\" data-end=\"3753\">Remote Procedure Call (RPC)<\/strong> allows seamless communication in distributed systems by enabling a client to execute methods on a remote server. Java <strong data-start=\"3872\" data-end=\"3906\">RMI (Remote Method Invocation)<\/strong> is one of the simplest implementations of RPC. <strong data-start=\"3954\" data-end=\"3977\">Modern alternatives<\/strong> like <strong data-start=\"3983\" data-end=\"4005\">gRPC and REST APIs<\/strong> provide more advanced and scalable solutions.<\/p>\n<p class=\"\" data-start=\"4055\" data-end=\"4110\">Would you like a <strong data-start=\"4072\" data-end=\"4106\">detailed guide on gRPC in Java<\/strong>?<\/p>\n<p data-start=\"0\" data-end=\"164\">Here is a clear and beginner-friendly explanation of <strong data-start=\"53\" data-end=\"84\">Remote Procedure Call (RPC)<\/strong>, with a specific focus on <strong data-start=\"111\" data-end=\"123\">Java RPC<\/strong> and its role in <strong data-start=\"140\" data-end=\"163\">Distributed Systems<\/strong>.<\/p>\n<hr data-start=\"166\" data-end=\"169\" \/>\n<h2 data-start=\"171\" data-end=\"217\">\ud83d\udcd8 <strong data-start=\"177\" data-end=\"217\">What is Remote Procedure Call (RPC)?<\/strong><\/h2>\n<h3 data-start=\"219\" data-end=\"241\">\ud83d\udd39 <strong data-start=\"226\" data-end=\"241\">Definition:<\/strong><\/h3>\n<p data-start=\"242\" data-end=\"427\"><strong data-start=\"242\" data-end=\"273\">Remote Procedure Call (RPC)<\/strong> is a protocol that allows a program to <strong data-start=\"313\" data-end=\"344\">call a function (procedure)<\/strong> on <strong data-start=\"348\" data-end=\"383\">another machine (remote server)<\/strong> as if it were calling a <strong data-start=\"408\" data-end=\"426\">local function<\/strong>.<\/p>\n<p data-start=\"429\" data-end=\"450\">\ud83d\udccc In simple words:<\/p>\n<blockquote data-start=\"451\" data-end=\"580\">\n<p data-start=\"453\" data-end=\"580\">&#8220;A function on one computer calls a function on another computer over the network, and it works like a regular local function.&#8221;<\/p>\n<\/blockquote>\n<hr data-start=\"582\" data-end=\"585\" \/>\n<h2 data-start=\"587\" data-end=\"617\">\ud83e\udde0 <strong data-start=\"593\" data-end=\"617\">Key Concepts of RPC:<\/strong><\/h2>\n<div class=\"_tableContainer_16hzy_1\">\n<div class=\"_tableWrapper_16hzy_14 group flex w-fit flex-col-reverse\">\n<table class=\"w-fit min-w-(--thread-content-width)\" data-start=\"619\" data-end=\"1122\">\n<thead data-start=\"619\" data-end=\"690\">\n<tr data-start=\"619\" data-end=\"690\">\n<th data-start=\"619\" data-end=\"636\" data-col-size=\"sm\">Concept<\/th>\n<th data-start=\"636\" data-end=\"690\" data-col-size=\"md\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"763\" data-end=\"1122\">\n<tr data-start=\"763\" data-end=\"834\">\n<td data-start=\"763\" data-end=\"780\" data-col-size=\"sm\">Client<\/td>\n<td data-start=\"780\" data-end=\"834\" data-col-size=\"md\">Sends the function call to the server<\/td>\n<\/tr>\n<tr data-start=\"835\" data-end=\"906\">\n<td data-start=\"835\" data-end=\"852\" data-col-size=\"sm\">Server<\/td>\n<td data-start=\"852\" data-end=\"906\" data-col-size=\"md\">Executes the requested function<\/td>\n<\/tr>\n<tr data-start=\"907\" data-end=\"978\">\n<td data-start=\"907\" data-end=\"924\" data-col-size=\"sm\">Stub<\/td>\n<td data-start=\"924\" data-end=\"978\" data-col-size=\"md\">A small piece of code that handles network details<\/td>\n<\/tr>\n<tr data-start=\"979\" data-end=\"1050\">\n<td data-start=\"979\" data-end=\"996\" data-col-size=\"sm\">Marshalling<\/td>\n<td data-col-size=\"md\" data-start=\"996\" data-end=\"1050\">Converts arguments\/data into byte format<\/td>\n<\/tr>\n<tr data-start=\"1051\" data-end=\"1122\">\n<td data-start=\"1051\" data-end=\"1068\" data-col-size=\"sm\">Unmarshalling<\/td>\n<td data-start=\"1068\" data-end=\"1122\" data-col-size=\"md\">Converts response bytes back to usable data<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"sticky end-(--thread-content-margin) h-0 self-end select-none\">\n<div class=\"absolute end-0 flex items-end\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"1124\" data-end=\"1127\" \/>\n<h2 data-start=\"1129\" data-end=\"1165\">\ud83c\udf10 <strong data-start=\"1135\" data-end=\"1165\">RPC in Distributed Systems<\/strong><\/h2>\n<p data-start=\"1167\" data-end=\"1190\">In distributed systems:<\/p>\n<ul data-start=\"1191\" data-end=\"1377\">\n<li data-start=\"1191\" data-end=\"1276\">\n<p data-start=\"1193\" data-end=\"1276\">Components of an application are <strong data-start=\"1226\" data-end=\"1275\">distributed across different nodes (machines)<\/strong>.<\/p>\n<\/li>\n<li data-start=\"1277\" data-end=\"1377\">\n<p data-start=\"1279\" data-end=\"1377\">RPC helps in <strong data-start=\"1292\" data-end=\"1323\">communication between nodes<\/strong> by allowing them to <strong data-start=\"1344\" data-end=\"1376\">invoke each other\u2019s services<\/strong>.<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"1379\" data-end=\"1404\">\ud83c\udfaf <strong data-start=\"1382\" data-end=\"1404\">Example Use Cases:<\/strong><\/p>\n<ul data-start=\"1405\" data-end=\"1480\">\n<li data-start=\"1405\" data-end=\"1439\">\n<p data-start=\"1407\" data-end=\"1439\">Microservices calling each other<\/p>\n<\/li>\n<li data-start=\"1440\" data-end=\"1452\">\n<p data-start=\"1442\" data-end=\"1452\">Cloud APIs<\/p>\n<\/li>\n<li data-start=\"1453\" data-end=\"1480\">\n<p data-start=\"1455\" data-end=\"1480\">Database service requests<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"1482\" data-end=\"1485\" \/>\n<h2 data-start=\"1487\" data-end=\"1523\">\ud83e\uddd1\u200d\ud83d\udcbb <strong data-start=\"1496\" data-end=\"1523\">Java RPC \u2013 How it Works<\/strong><\/h2>\n<p data-start=\"1525\" data-end=\"1587\">Java has various ways to implement RPC-like behavior, such as:<\/p>\n<h3 data-start=\"1589\" data-end=\"1636\">1. <strong data-start=\"1596\" data-end=\"1636\">Java RMI (Remote Method Invocation):<\/strong><\/h3>\n<ul data-start=\"1637\" data-end=\"1717\">\n<li data-start=\"1637\" data-end=\"1669\">\n<p data-start=\"1639\" data-end=\"1669\">Built-in RPC mechanism in Java<\/p>\n<\/li>\n<li data-start=\"1670\" data-end=\"1717\">\n<p data-start=\"1672\" data-end=\"1717\">Allows calling methods on remote Java objects<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"1719\" data-end=\"1734\">\ud83d\udccc <strong data-start=\"1722\" data-end=\"1734\">Example:<\/strong><\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\">java<\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre! language-java\"><code class=\"whitespace-pre! language-java\"><span class=\"hljs-comment\">\/\/ Remote Interface<\/span><br \/>\n<span class=\"hljs-keyword\">import<\/span> java.rmi.*;<\/code><\/code><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">interface<\/span> <span class=\"hljs-title class_\">Hello<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title class_\">Remote<\/span> {<br \/>\nString <span class=\"hljs-title function_\">sayHello<\/span><span class=\"hljs-params\">()<\/span> <span class=\"hljs-keyword\">throws<\/span> RemoteException;<br \/>\n}<\/div>\n<\/div>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\">java<\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre! language-java\"><code class=\"whitespace-pre! language-java\"><span class=\"hljs-comment\">\/\/ Server Implementation<\/span><br \/>\n<span class=\"hljs-keyword\">import<\/span> java.rmi.server.UnicastRemoteObject;<br \/>\n<span class=\"hljs-keyword\">import<\/span> java.rmi.*;<\/code><\/code><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">HelloImpl<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title class_\">UnicastRemoteObject<\/span> <span class=\"hljs-keyword\">implements<\/span> <span class=\"hljs-title class_\">Hello<\/span> {<br \/>\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-title function_\">HelloImpl<\/span><span class=\"hljs-params\">()<\/span> <span class=\"hljs-keyword\">throws<\/span> RemoteException {}<br \/>\n<span class=\"hljs-keyword\">public<\/span> String <span class=\"hljs-title function_\">sayHello<\/span><span class=\"hljs-params\">()<\/span> {<br \/>\n<span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">&#8220;Hello from Server!&#8221;<\/span>;<br \/>\n}<br \/>\n}<\/div>\n<\/div>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\">java<\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre! language-java\"><code class=\"whitespace-pre! language-java\"><span class=\"hljs-comment\">\/\/ Client<\/span><br \/>\n<span class=\"hljs-keyword\">import<\/span> java.rmi.*;<\/code><\/code><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">Client<\/span> {<br \/>\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title function_\">main<\/span><span class=\"hljs-params\">(String[] args)<\/span> <span class=\"hljs-keyword\">throws<\/span> Exception {<br \/>\n<span class=\"hljs-type\">Hello<\/span> <span class=\"hljs-variable\">stub<\/span> <span class=\"hljs-operator\">=<\/span> (Hello) Naming.lookup(<span class=\"hljs-string\">&#8220;rmi:\/\/localhost:5000\/hello&#8221;<\/span>);<br \/>\nSystem.out.println(stub.sayHello());<br \/>\n}<br \/>\n}<\/div>\n<\/div>\n<hr data-start=\"2428\" data-end=\"2431\" \/>\n<h3 data-start=\"2433\" data-end=\"2479\">2. <strong data-start=\"2440\" data-end=\"2479\">Modern Alternatives to RPC in Java:<\/strong><\/h3>\n<div class=\"_tableContainer_16hzy_1\">\n<div class=\"_tableWrapper_16hzy_14 group flex w-fit flex-col-reverse\">\n<table class=\"w-fit min-w-(--thread-content-width)\" data-start=\"2481\" data-end=\"2815\">\n<thead data-start=\"2481\" data-end=\"2547\">\n<tr data-start=\"2481\" data-end=\"2547\">\n<th data-start=\"2481\" data-end=\"2498\" data-col-size=\"sm\">Technology<\/th>\n<th data-start=\"2498\" data-end=\"2547\" data-col-size=\"md\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"2615\" data-end=\"2815\">\n<tr data-start=\"2615\" data-end=\"2681\">\n<td data-start=\"2615\" data-end=\"2634\" data-col-size=\"sm\">gRPC (by Google)<\/td>\n<td data-col-size=\"md\" data-start=\"2634\" data-end=\"2681\">High-performance, open-source RPC framework<\/td>\n<\/tr>\n<tr data-start=\"2682\" data-end=\"2748\">\n<td data-start=\"2682\" data-end=\"2700\" data-col-size=\"sm\">Spring REST<\/td>\n<td data-col-size=\"md\" data-start=\"2700\" data-end=\"2748\">Using HTTP to simulate RPC calls<\/td>\n<\/tr>\n<tr data-start=\"2749\" data-end=\"2815\">\n<td data-start=\"2749\" data-end=\"2767\" data-col-size=\"sm\">Apache Thrift<\/td>\n<td data-start=\"2767\" data-end=\"2815\" data-col-size=\"md\">Language-agnostic RPC framework<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"sticky end-(--thread-content-margin) h-0 self-end select-none\">\n<div class=\"absolute end-0 flex items-end\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"2817\" data-end=\"2820\" \/>\n<h2 data-start=\"2822\" data-end=\"2851\">\ud83d\udd04 <strong data-start=\"2828\" data-end=\"2851\">RPC vs REST vs gRPC<\/strong><\/h2>\n<div class=\"_tableContainer_16hzy_1\">\n<div class=\"_tableWrapper_16hzy_14 group flex w-fit flex-col-reverse\">\n<table class=\"w-fit min-w-(--thread-content-width)\" data-start=\"2853\" data-end=\"3429\">\n<thead data-start=\"2853\" data-end=\"2948\">\n<tr data-start=\"2853\" data-end=\"2948\">\n<th data-start=\"2853\" data-end=\"2869\" data-col-size=\"sm\">Feature<\/th>\n<th data-start=\"2869\" data-end=\"2894\" data-col-size=\"sm\">RPC<\/th>\n<th data-start=\"2894\" data-end=\"2920\" data-col-size=\"sm\">REST<\/th>\n<th data-start=\"2920\" data-end=\"2948\" data-col-size=\"sm\">gRPC<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"3046\" data-end=\"3429\">\n<tr data-start=\"3046\" data-end=\"3141\">\n<td data-start=\"3046\" data-end=\"3062\" data-col-size=\"sm\">Protocol<\/td>\n<td data-col-size=\"sm\" data-start=\"3062\" data-end=\"3087\">TCP<\/td>\n<td data-col-size=\"sm\" data-start=\"3087\" data-end=\"3113\">HTTP<\/td>\n<td data-col-size=\"sm\" data-start=\"3113\" data-end=\"3141\">HTTP\/2<\/td>\n<\/tr>\n<tr data-start=\"3142\" data-end=\"3237\">\n<td data-start=\"3142\" data-end=\"3158\" data-col-size=\"sm\">Format<\/td>\n<td data-col-size=\"sm\" data-start=\"3158\" data-end=\"3183\">Binary or custom<\/td>\n<td data-col-size=\"sm\" data-start=\"3183\" data-end=\"3209\">JSON<\/td>\n<td data-col-size=\"sm\" data-start=\"3209\" data-end=\"3237\">Protocol Buffers<\/td>\n<\/tr>\n<tr data-start=\"3238\" data-end=\"3333\">\n<td data-start=\"3238\" data-end=\"3254\" data-col-size=\"sm\">Performance<\/td>\n<td data-start=\"3254\" data-end=\"3279\" data-col-size=\"sm\">Fast (less overhead)<\/td>\n<td data-start=\"3279\" data-end=\"3305\" data-col-size=\"sm\">Slower (text-based)<\/td>\n<td data-start=\"3305\" data-end=\"3333\" data-col-size=\"sm\">Very fast<\/td>\n<\/tr>\n<tr data-start=\"3334\" data-end=\"3429\">\n<td data-start=\"3334\" data-end=\"3350\" data-col-size=\"sm\">Use Case<\/td>\n<td data-col-size=\"sm\" data-start=\"3350\" data-end=\"3375\">Internal services<\/td>\n<td data-col-size=\"sm\" data-start=\"3375\" data-end=\"3401\">Web APIs<\/td>\n<td data-col-size=\"sm\" data-start=\"3401\" data-end=\"3429\">Microservices<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"sticky end-(--thread-content-margin) h-0 self-end select-none\">\n<div class=\"absolute end-0 flex items-end\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"3431\" data-end=\"3434\" \/>\n<h2 data-start=\"3436\" data-end=\"3449\">\ud83d\udccc Summary<\/h2>\n<ul data-start=\"3451\" data-end=\"3672\">\n<li data-start=\"3451\" data-end=\"3515\">\n<p data-start=\"3453\" data-end=\"3515\"><strong data-start=\"3453\" data-end=\"3460\">RPC<\/strong> = call a function on another machine as if it&#8217;s local.<\/p>\n<\/li>\n<li data-start=\"3516\" data-end=\"3582\">\n<p data-start=\"3518\" data-end=\"3582\">Java supports RPC via <strong data-start=\"3540\" data-end=\"3547\">RMI<\/strong>, <strong data-start=\"3549\" data-end=\"3557\">gRPC<\/strong>, <strong data-start=\"3559\" data-end=\"3576\">Apache Thrift<\/strong>, etc.<\/p>\n<\/li>\n<li data-start=\"3583\" data-end=\"3672\">\n<p data-start=\"3585\" data-end=\"3672\">In <strong data-start=\"3588\" data-end=\"3611\">Distributed Systems<\/strong>, RPC helps decouple components while enabling communication.<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"3674\" data-end=\"3677\" \/>\n<h2 data-start=\"3679\" data-end=\"3695\">\ud83d\udce6 Need More?<\/h2>\n<p data-start=\"3697\" data-end=\"3712\">Would you like:<\/p>\n<ul data-start=\"3713\" data-end=\"3844\">\n<li data-start=\"3713\" data-end=\"3739\">\n<p data-start=\"3715\" data-end=\"3739\">A <strong data-start=\"3717\" data-end=\"3738\">Java gRPC example<\/strong>?<\/p>\n<\/li>\n<li data-start=\"3740\" data-end=\"3800\">\n<p data-start=\"3742\" data-end=\"3800\">A <strong data-start=\"3744\" data-end=\"3768\">YouTube video script<\/strong> explaining RPC with animations?<\/p>\n<\/li>\n<li data-start=\"3801\" data-end=\"3844\">\n<p data-start=\"3803\" data-end=\"3844\">A <strong data-start=\"3805\" data-end=\"3820\">PDF handout<\/strong> with code and diagrams?<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"3846\" data-end=\"3900\" data-is-last-node=\"\" data-is-only-node=\"\">Let me know, and I\u2019ll prepare it for you step-by-step!<\/p>\n<h3 data-start=\"3846\" data-end=\"3900\"><a href=\"https:\/\/people.cs.rutgers.edu\/~pxk\/417\/notes\/content\/03-rpc-slides.pdf\" target=\"_blank\" rel=\"noopener\">Remote Procedure Call-RPC define procedure java rpc-Remote Procedure Call in Distributed System<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/lia.disi.unibo.it\/Courses\/PMA4DS1415\/materiale\/11.RPC-RMI%20x4.pdf\" target=\"_blank\" rel=\"noopener\">Remote Procedure Call Remote Procedure Call (RPC)<\/a><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>Remote Procedure Call-RPC define procedure java rpc-Remote Procedure Call in Distributed System.<\/p>\n","protected":false},"author":64,"featured_media":2554,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[84],"tags":[2072,2073,2074,2075,2076,2077],"class_list":["post-2553","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-distributed-computing","tag-remote-procedure-call-rpc-service","tag-remote-procedure-call-example","tag-remote-procedure-call-in-computer-network-pdf","tag-remote-procedure-call-in-distributed-system","tag-remote-procedure-call-program-in-java","tag-rpc-example"],"_links":{"self":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts\/2553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/users\/64"}],"replies":[{"embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/comments?post=2553"}],"version-history":[{"count":0,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts\/2553\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/media\/2554"}],"wp:attachment":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/media?parent=2553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/categories?post=2553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/tags?post=2553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}