0% found this document useful (0 votes)
10 views11 pages

DCL - Experiment 3 1

The document outlines an experiment for a Distributed Computing Lab course, focusing on implementing a calculator application using Remote Method Invocation (RMI). It includes Python code for both the server and client, as well as observations and conclusions about the implementation process. Additionally, it addresses concepts like stubs, marshalling, and unmarshalling in the context of distributed computing.

Uploaded by

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

DCL - Experiment 3 1

The document outlines an experiment for a Distributed Computing Lab course, focusing on implementing a calculator application using Remote Method Invocation (RMI). It includes Python code for both the server and client, as well as observations and conclusions about the implementation process. Additionally, it addresses concepts like stubs, marshalling, and unmarshalling in the context of distributed computing.

Uploaded by

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

G. V.

Acharya Institute of Engineering & Technology


Computer Engineering Department
Program: Sem VIII

Course: Distributed Computing Lab (CSL802)

Faculty: Narayan Kharje

Experiment No. 3

A.1 Aim: To Implement any application using RMI/RPC.

PART B
(PART B: TO BE COMPLETED BY STUDENTS)

Roll No. Name:

Class: Batch:

Date of Experiment: Date of Submission:

Grade:
B.1 Software Code written by student:

● Server.py

import Pyro4 import


random import os
import datetime import
subprocess import
math

now=datetime.datetime.now()
print('date: '+now.strftime('%d-%m-%y')+' Time:'+now.strftime('%H:%M:%S'))
@Pyro4.expose

class Server(object):
def get_usid(self, name): return "Hello,
{0}.\n" \
"Your Current User Session is {1}:".format(name, random.randint(0,1000))

1
def add(self, a, b): return "{0} + {1} =
{2}".format(a, b, a+b)
def subtract(self, a, b): return "{0} - {1} = {2}".format(a,
b, a-b)

def multiply(self, a, b): return "{0} * {1} =


{2}".format(a, b, a*b)

def division(self, a, b): return "{0} / {1} =


{2}".format(a, b, a/b)

def sqr(self, a): return "{0} ^ 2 =


{1}".format(a, a**2)

def sqrt(self, a): return "sqrt({0}) = {1}".format(a,


math.sqrt(a))

def mod(self, a, b): return "{0} % {1} =


{2}".format(a, b, a%b)

def per(self, a, b): return "( {0} / {1} ) * 100 = {2}".format(a,


b, (a/b)*100)

def exp(self, a, b): return "{0} ** {1} =


{2}".format(a, b, a**b)

daemon = Pyro4.Daemon() ns = Pyro4.locateNS() url = daemon.register(Server)


ns.register("RMI.calculator", url) print("The Server is now active., please request your
calculations or start file transfer")

daemon.requestLoop()

● Client.py

import Pyro4
import os import
datetime Client =
Pyro4.Proxy("PYR
ONAME:RMI.calc
ulator") name
=input("What is your
name? ").strip()

2
now=datetime.da
tetime.now()

print('date: '+now.strftime('%d-%m-%y')+' Time:'+now.strftime('%H:%M:%S'))


print(Client.get_usid(name))
print("Enter the number of calculations to be done") n=int(input("Enter n: "))

while (n>0): n=n-1


print() a =int(input("Enter
a: ")) b =int(input("Enter b:
"))

print("Enter number for desired calculations: \n" +'1.ADD \n'+'2.SUBTRACT \n'+


'3.MULTIPLY \n'+ '4.DIVISION \n'+'5.SQUARE \n'+'6.SQRT \n'+ '7.MOD
\n'+ '8.PERCENTAGE \n'+'9.EXPONENTIATION')

c=int(input('Enter your choice: '))

if (c==1): print(Client.add(a,b)) elif


(c==2): print(Client.subtract(a,b))
elif (c==3):
print(Client.multiply(a,b)) elif
(c==4): print(Client.division(a,b)) elif
(c==5): print(Client.sqr(a)) elif
(c==6): print(Client.sqrt(a)) elif
(c==7): print(Client.mod(a,
b))
elif (c==8): print(Client.per(a,
b))
elif (c==9):
print(Client.exp(a, b))
else: print('invalid input')
B.2 Input and Output:

3
1. ADDITION

4
5
3. MULTIPLICATION

5. SQUARE

6
7. MOD

7
9. EXPONENTIATION

8
B.3 Observations and learning:
In a distributed computing environment, remote method invocation (RMI) refers to calling a
method on a remote object. It is analogous to a remote procedure call.

B.4 Conclusion:
Successfully implemented a calculator application using RMI.

B.5 Question of Curiosity.


Q1: What do you mean by stub? What are the functions of Stub?
ANS:
- A method stub or simply stub in software development is a piece of code used to stand
in for some other programming functionality. A stub may simulate the behaviour of
existing code (such as a procedure on a remote machine; such methods are often called
mocks) or be a temporary substitute for yet-to-be-developed code.

Q2: What is marshalling and unmarshalling?


ANS:
- Marshalling is the process of transforming the memory representation of an object into
another format, which is suitable for storage or transmission to other software
applications.

9
- Unmarshalling is the process in which an object or data structure is deserialized.

10
Q3: How is the stub generated?
ANS:
- Stubs are generated either manually or automatically. In a manual generation, a remote
procedure call implementer provides translation functions, from which a user
constructs stubs. They handle complex parameter types. Automatic stub generation is
commonly used to generate stubs. They use integration description language to define
client and server interfaces.

11

You might also like