0% found this document useful (0 votes)
88 views5 pages

11 Remote Method Invocation Using Python

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 5

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/341271544

Remote Method Invocation Using Python

Article · January 2017

CITATIONS READS

0 7,576

3 authors, including:

Het Sheth Pratik Kanani


University of Massachusetts Lowell Dwarkadas J. Sanghvi College of Engineering
1 PUBLICATION 0 CITATIONS 83 PUBLICATIONS 269 CITATIONS

SEE PROFILE SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Security in next generation networks View project

Political implications of Xenophobia View project

All content following this page was uploaded by Pratik Kanani on 09 May 2020.

The user has requested enhancement of the downloaded file.


INTERNATIONAL JOURNAL OF ADVANCED STUDIES
IN COMPUTER SCIENCE AND ENGINEERING 11/30/2017
IJASCSE VOLUME 6 ISSUE 11, 2017

Remote Method Invocation Using Python


Ashwini Swain Het Sheth
ashwinswain84@gmail.com hetpsheth@gmail.com
Student, IT Department, D. J. Sanghvi College of Engineering, Vile Parle, Mumbai, India.
Pratik Kanani
pratikkanani123@gmail.com
Assistant Professor, Computer Department, D. J. Sanghvi College of Engineering, Vile Parle, Mumbai, India.

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: '))

if (c==1): Fig.5. Running the Second Client


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.exp(a))
else:
print('invalid input')

WWW.IJASCSE.ORG 36
INTERNATIONAL JOURNAL OF ADVANCED STUDIES
IN COMPUTER SCIENCE AND ENGINEERING 11/30/2017
IJASCSE VOLUME 6 ISSUE 11, 2017

[7] Summerfield, Mark. Rapid GUI Programming with Python


C. FUTURE SCOPE and Qt. "Python is a very expressive language, which means
that we can usually write far fewer lines of Python code than
The use of Java to implement RMI has made it would be required for an equivalent application written in, say,
C++ or Java"
possible to call methods of the server and also send or [8] Benchmarksgame.alioth.debian.org. (2017). Python 3 vs Java
transfer files from one node (or host) to another. On (64-bit Ubuntu quad core) | Computer Language Benchmarks
the other hand, despite of the ease of calling of server Game. [online] Available at:
method using Pyro, transferring files from one https://benchmarksgame.alioth.debian.org/u64q/python.html
destination to another has proved to be cumbersome. [Accessed 20 Sep. 2017].
Linux commands had to be embedded into the script. [9] Anon, (2017). [online] Available at:
https://www.ijser.org/researchpaper/Implementation-of-
The subprocess package and the os module available Socket-Programming-and-RMI-Using-Simulating-
with Python were also used, through which the files Environment.pdf [Accessed 19 Sep. 2017].
were transferred from the server source to the [10] Q. Charatan and A. Kans, ”Java in two semesters” , 2nd edition
destination using Linux Commands. This poses a McGraw Hills publication,2006
problem for implementing RMI on machines that do [11] En.wikipedia.org. (2017). RMI-IIOP. [online] Available at:
not support Linux, for example, Windows. Thus, https://en.wikipedia.org/wiki/RMI-IIOP [Accessed 19 Sep.
2017].
future research should focus on transferring files using
[12] Webopedia.com. (2017). What is Client Server Architecture?
Pyro (or any other Python equivalent) such that the Webopedia Definition. [online] Available at:
cross platform problems are mitigated. http://www.webopedia.com/TERM/C/client_server_architect
ure.html [Accessed 19 Sep. 2017].
D. CONCLUSION [13] "About Python". Python Software Foundation., second
section "Fans of Python use the phrase "batteries included" to
This paper documents attempts made to complete an describe the standard library, which covers everything from
end to end RMI system. We have succeeded in asynchronous processing to zip files."
[14] Pythonhosted.org. (2017). Pyro - Python Remote Objects -
implementing the ubiquitous Remote Method
4.60 — Pyro 4.60 documentation. [online] Available at:
Invocation using Python. This idea can be carried https://pythonhosted.org/Pyro4/ [Accessed 19 Sep. 2017].
forward and used to make more complex systems in [15] En.wikibooks.org. (2017). Communication Networks/TCP
the future. Although the prominence of Java in and UDP Protocols - Wikibooks, open books for an open
implementing RMI cannot be compared to that of world. [online] Available at:
Python, the impact that Python would have in this https://en.wikibooks.org/wiki/Communication_Networks/TC
P_and_UDP_Protocols [Accessed 26 Sep. 2017].
domain cannot be ignored. With the ever increasing
[16] Cs.dartmouth.edu. (2017). [online] Available at:
community, it is possible that Python may supplant http://www.cs.dartmouth.edu/~campbell/cs60/socketprogram
Java in the field of Distributed Computing in the ming.html [Accessed 26 Sep. 2017].
coming future.

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

View publication stats

You might also like