11 Remote Method Invocation Using Python
11 Remote Method Invocation Using Python
11 Remote Method Invocation Using Python
net/publication/341271544
CITATIONS READS
0 7,576
3 authors, including:
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Pratik Kanani on 09 May 2020.
Abstract- In today's continuously evolving world, it is not within a program [4]. But, RPC uses the structured
possible to store all the data or do all the computations on programming approach, which can be improved by
a single machine. So the concept of Distributed Computing using object oriented models. The principle of objects
is widely used which helps in efficient storage and can be applied to handle objects, that is, invocation of
transmission of data over the network. For the proper
remote objects. Using this approach, objects in different
transmission of data, techniques like RMI (Remote
Method Invocation) and RPC (Remote Procedure Call) procedures can communicate with each other through
can be used. RMI and RPC are mostly implemented in Remote Method Invocation (RMI) [5].
Java. This paper aims to implement RMI in Python, which RMI has traditionally been done in Java as it is an
is the fastest growing language, and give an idea about how
object oriented programming language and thus the
it can be advantageous over Java. Python has been used in
many domains like Cyber Security, Data Science, Artificial capability of handling objects and working on cross
Intelligence, Networking and the Web. This paper platform problems can be integrated efficiently in Java.
documents one such novel application of Python in the field It works by creating a stub- which is a request from the
of distributed computing by implementing Remote client. This stub is captured by the skeletons of the
Method Invocation using Python. server. Thus generation of stubs and skeletons is must
for implementing RMI in Java. To escape this
Keywords— Remote Method Invocation; Java; Python; intermediate stage, Python can be used, which is another
Pyro; Distributed Computing. object oriented programming language.
I. INTRODUCTION Python is a general purpose high level dynamic
language which can be used to implement RMI [6]. The
It is important for people to have access to advantage of using Python is its readability and its
information as it aids in developing problem solving ability to build efficient systems in a limited number of
approaches and thinking skills, forming opinions, lines of code [7]. It is robust, flexible and secure, just
evaluating various parameters and making informed like Java. The only disadvantage is that it is a bit slower
decisions, fostering successful learners and confident than Java, but this can be overlooked considering its
individuals [1]. Thus, making this information available functionality [8]. Python is written internally in C, and
to all is a very crucial task. Generally, this is done using thus all the Python code is first interpreted into its C
networked systems which have interconnected nodes, equivalent, which makes it slower than languages like
usually a personal computer, a mainframe or any other Java and C.
device [2], over vast geographical areas. However, the
level of transparency of these systems is low and the In the era of data analytics and big data, it has
user is completely aware of the different systems he is become necessary to transfer data files remotely from
working on. The remedy to this problem is making use server to client. In such a scenario, RMI can prove to be
of Distributed Systems which allow the same facility but efficient in transferring data files. Java is not used for
with increased transparency [3]. data science but Python is a leader in this domain, which
implies that using RMI in Python can eliminate the
A Distributed System signifies a single system burden of cross-language problems.
consisting of multiple computers connected by a high
speed network. The main idea behind using a distributed II. LITERATURE REVIEW
system is that a system having multiple resources will
provide us a shorter response time and better throughput Socket Programming has been the traditional way
than a single processor system. This need for a of enabling communication and establishing
distributed system led to the formation of a RPC model connections between a server and a client. A socket
similar to the more common Local Procedure Call serves various clients with different types of information
(LPC) model that is used to transfer data and control by using only a single computer and introducing a
WWW.IJASCSE.ORG 34
INTERNATIONAL JOURNAL OF ADVANCED STUDIES
IN COMPUTER SCIENCE AND ENGINEERING 11/30/2017
IJASCSE VOLUME 6 ISSUE 11, 2017
numbered socket, commonly known as a port, on the each other over a network [14]. Normal Python method
computer. [9]. The server waits and listens to the socket calls can be used to pass any type of arguments and
for a client to make a connection request. The two types make a remote call to the server objects. Some of Pyro’s
of sockets are Transmission Control Protocol (TCP) advantages include:
which are connection-oriented and User Datagram It is written in Pure Python Language and is thus
Protocol (UDP) which are connectionless [15]. Even system and platform independent.
though multiple clients can connect on a single port, It can work on cross-platform architectures and
these connections are unique [10]. But to overcome the different operating system at the same time.
limitations of Socket programming like security issues
It can accept any type of parameters for method
and the constraint of only sending raw data, RMI was
introduced. Figure 1 [16] shows a situation where the passing and can return any type of value.
client and server are both on the same local network
III. PROPOSED MODEL
RMI can be implemented in python using socket
programming. In this, the requests from the client are
first converted into objects and these objects then invoke
the methods of the server over the network. But the
problem with this is that effort needed for programming
is still high. For reducing the time spent programming
it, RMI can be implemented using the Pyro library. It
has been renamed to Pyro4 in Python 3. It enables
developers to build applications such that objects can
talk to each other over a network. The developer need
not worry about creating the objects and locating or
porting the correct object. Pyro can be used to make
function calls in the traditional Python way and locating
the correct object of the correct method is handled by
Pyro. Since, as many clients as needed can be connected,
Pyro can be used in creating an efficient Distributed
Fig.1. Client and server on the same local network System in Python.
RMI was developed by Sun Microsystems and
IBM [11]. It has traditionally been done in Java. It
IV. WORKING OF THE SYSTEM
involves establishing client-server architecture and
calling a method or an object remotely. In such an The following steps need to be executed in different
architecture, a machine on the network functions either command prompts or Terminals in order to run the
as a server or as a client. Servers are robust machines system. Localhost is required to start the server.
that manage either disk drives and printers or network
traffic. On the other hand, the client side, also known as 1) Start the Proxy Localhost at the default port 9090.
a workstation, consist of machines on which the users 2) Run the Server
run applications. The client side machines are dependent 3) Run the clients.
on the servers for resources and processing power [12]. Commands for the above steps are:
Two objects are created for the effective implementation
of RMI. The first one is the Server Object which is the Start the localhost-->python3 -m Pyro4.naming
remote object that is called. Second one is the Client Start the Server--> python3 Server.py
object which is an object whose method makes a remote Start the Client--> python3 Client.py
call.
For enabling the client to properly locate the server, it
Python supports various programming models such needs to be named and registered with the localhost,
as functional, procedural and object-oriented similar to registering with the RMI registry in Java. It is
programming. It has a large and comprehensive standard done by using the following instructions:
library coupled with other features such as automatic
memory management and a dynamic type system [13]. url = daemon.register(Server)
The extensive number of libraries supporting Python has ns.register("RMI.calculator", url)
made implementing RMI possible in it. The process is The server is named as RMI.calculator and it is
similar to the former procedure, creating server registered with the daemon registry. The Client locates
methods, server objects and calling it with the client the Server with the help of the following code:
object locally. The only thing that doesn't take part here
is the generation of stubs and skeletons. Client = Pyro4.Proxy("PYRONAME:RMI.calculator")
Pyro has been benevolent to developers by Now the Client variable acts as an object of the Client.
providing a library that enables them to build This object can now invoke methods defined in the
applications in which objects can communicate with server and can accept any parameters from the client.
WWW.IJASCSE.ORG 35
INTERNATIONAL JOURNAL OF ADVANCED STUDIES
IN COMPUTER SCIENCE AND ENGINEERING 11/30/2017
IJASCSE VOLUME 6 ISSUE 11, 2017
A. Server Code: The figures shown below depict the execution of the
import Pyro4 three steps mentioned above.
import random
import os A. LocalHost:
import datetime
import subprocess
now=datetime.datetime.now()
print('date: '+now.strftime('%d-%m-%y')+' Time:
'+now.strftime('%H:%M:%S'))
@Pyro4.expose Fig.2. Starting the LocalHost
class Server(object):
def get_usid(self, name): B. Server:
return "Hello, {0}.\n" \
"Your Current User Session is {1}:".format(name,
random.randint(0,1000))
def add(self, a, b):
return "{0} + {1} = {2}".format(a, b, a+b) Fig.3. Running the Server
def subtract(self, a, b):
return "{0} - {1} = {2}".format(a, b, a-b) C. Client-1:
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 exp(self, a):
return "{0} ** {1} = {2}".format(a, a, a**a)
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()
B. Client Code:
import Pyro4
import os
import datetime Fig.4. Running the First Client
Client = Pyro4.Proxy("PYRONAME:RMI.calculator")
name =input("What is your name? ").strip() D. Client-2:
now=datetime.datetime.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
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.EXPONENTIATION \n')
c=int(input('Enter your choice: '))
WWW.IJASCSE.ORG 36
INTERNATIONAL JOURNAL OF ADVANCED STUDIES
IN COMPUTER SCIENCE AND ENGINEERING 11/30/2017
IJASCSE VOLUME 6 ISSUE 11, 2017
REFERENCES
[1] Therightinformation.org. (2017). Information Skills for a 21st
Century Scotland - Information Literacy: The Importance of.
[online] Available at:
http://www.therightinformation.org/realrelevant-
importanceof/ [Accessed 9 Sep. 2017].
[2] A. Raju,” Advanced Java”
[3] Anon, (2017). [online] Available at:
https://www.cis.upenn.edu/~lee/07cis505/Lec/lec-ch1-
DistSys-v4.pdf [Accessed 20 Sep. 2017].
[4] Users.cs.cf.ac.uk. (2017). Remote Procedure Calls (RPC).
[online] Available at:
https://users.cs.cf.ac.uk/Dave.Marshall/C/node33.html
[Accessed 20 Sep. 2017].
[5] En.wikipedia.org. (2017). Java remote method invocation.
[online] Available at:
https://en.wikipedia.org/wiki/Java_remote_method_invocatio
n [Accessed 20 Sep. 2017].
[6] "Programming Language Trends - O'Reilly Radar".
Radar.oreilly.com. 2 August 2006.
WWW.IJASCSE.ORG 37