0% found this document useful (0 votes)
5 views3 pages

Exp - 1 (DC)

The document discusses the study of a Client-Server based program using Remote Procedure Call (RPC) technology, which allows procedures to be executed on different systems over a network. It includes a Java implementation of both server and client code that performs basic arithmetic operations (addition, subtraction, multiplication, division) based on user input. The conclusion states that the RPC program was successfully studied and executed.

Uploaded by

andynatekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Exp - 1 (DC)

The document discusses the study of a Client-Server based program using Remote Procedure Call (RPC) technology, which allows procedures to be executed on different systems over a network. It includes a Java implementation of both server and client code that performs basic arithmetic operations (addition, subtraction, multiplication, division) based on user input. The conclusion states that the RPC program was successfully studied and executed.

Uploaded by

andynatekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Nikita Bhoir

AIM: To study Client Server based program using RPC.

 THEORY:
RPC is a powerful technique for constructing distributed, client-server-based applications. It is based on
extending the notion of conventional, or local procedure calling, so that the called procedure need not
exist in the same address space as the calling procedure. The two processes may be on the same system,
or they may be on different systems with a network connecting them. By using RPC, programmers of
distributed applications avoid the details of the interface with the network. The transport independence
of RPC isolates the application from the physical and logical elements of the data communications
mechanism and allows the application to use a variety of transports.
RPC makes the client/server model of computing more powerful and easier to program. When combined
with the ONC RPCGEN protocol compiler clients transparently make remote calls through a local
procedure interface.

An RPC is analogous to a function call. Like a function call, when an RPC is made, the calling arguments are
passed to the remote procedure and the caller waits for a response to be returned from the remote
procedure. Figure shows the flow of activity that takes place during an RPC call between two networked
systems. The client makes a procedure call that sends a request to the server and waits. The thread is
blocked from processing until either a reply is received, or it times out. When the request arrives, the
server calls a dispatch routine that performs the requested service, and sends the reply to the client. After
the RPC call is completed, the client program continues. RPC specifically supports network applications.

 Program Code:

import
java.io.*;
import
java.net.*;
class ser {

public static void main(String[] args) throws Exception


{ ServerSocket sersock = new ServerSocket(3000);
System.out.println("Server ready");
Socket sock = sersock.accept();
BufferedReader keyRead = new BufferedReader(new
InputStreamReader(System.in)); OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
InputStream istream = sock.getInputStream();
BufferedReader receiveRead = new BufferedReader(new
InputStreamReader(istream)); String receiveMessage, sendMessage, fun;
int a, b, c;
while
(true) {
fun =
receiveRead.readLine(); if
(fun != null) {
System.out.println("Operation : " + fun);
}
a = Integer.parseInt(receiveRead.readLine());
Nikita Bhoir

System.out.println("Parameter 1 : " + a);


b=
Integer.parseInt(receiveRead.readLine()
); if (fun.compareTo("add") == 0) {
c = a + b;
System.out.println("Addition = "
+ c); pwrite.println("Addition = "
+ c);
}
if (fun.compareTo("sub") ==
0) { c = a - b;
System.out.println("Substraction = " + c);
pwrite.println("Substraction = " + c);
}
if (fun.compareTo("mul") ==
0) { c = a * b;
System.out.println("Multiplication = " + c);
pwrite.println("Multiplication = " + c);
}
if (fun.compareTo("div") ==
0) { c = a / b;
System.out.println("Division = " + c);
pwrite.println("Division = " + c);
}
System.out.flush();
}
}

import
java.io.*;
import
java.net.*;

class cli {

public static void main(String[] args) throws Exception


{ Socket sock = new Socket("127.0.0.1", 3000);
BufferedReader keyRead = new BufferedReader(new
InputStreamReader(System.in)); OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
InputStream istream = sock.getInputStream();
BufferedReader receiveRead = new BufferedReader(new
InputStreamReader(istream)); System.out.println("Client ready, type and press
Enter key");
String receiveMessage,
sendMessage, temp; while (true) {
System.out.println("\nEnter operation to perform(add,sub,mul,div).
")
; temp = keyRead.readLine();
sendMessage =
temp.toLowerCase();
pwrite.println(sendMessage)
;
System.out.println("Enter first parameter
:"); sendMessage = keyRead.readLine();
pwrite.println(sendMessage);
System.out.println("Enter second
parameter : "); sendMessage =
Nikita Bhoir

keyRead.readL
ine();
pwrite.println(
sendMessage);
System.out.flus
h();
if ((receiveMessage =
receiveRead.readLine()) != null)
{ System.out.println(receiveMess
age);
}
}
}
}

 Output:

Enter first parameter :


84
Enter second parameter :
6
Addition = 90

Operation :
a
d
d

P
a
r
a
m
e
t
e
r

1
: 84
Parameter 2 : 6
Addition = 90

 Conclusion:

Hence, we have studied and run Client-Server based RPC program successfully

You might also like