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

Python Implementation of RMI

This document discusses implementing Remote Method Invocation (RMI) using Python. RMI allows objects located on different machines to communicate by invoking each other's methods over a network. Traditionally, RMI has been implemented in Java due to its object-oriented nature. The document proposes using Python as an alternative to Java for RMI, as Python is also object-oriented and has advantages like readability. It describes how RMI can be realized in Python using the Pyro library, which allows normal Python method calls to invoke server objects remotely without needing to generate stubs and skeletons as in Java RMI. Implementing RMI in Python can help transfer data files for tasks like data analytics more efficiently compared to other languages like Java

Uploaded by

Bhanu Naik
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)
64 views5 pages

Python Implementation of RMI

This document discusses implementing Remote Method Invocation (RMI) using Python. RMI allows objects located on different machines to communicate by invoking each other's methods over a network. Traditionally, RMI has been implemented in Java due to its object-oriented nature. The document proposes using Python as an alternative to Java for RMI, as Python is also object-oriented and has advantages like readability. It describes how RMI can be realized in Python using the Pyro library, which allows normal Python method calls to invoke server objects remotely without needing to generate stubs and skeletons as in Java RMI. Implementing RMI in Python can help transfer data files for tasks like data analytics more efficiently compared to other languages like Java

Uploaded by

Bhanu Naik
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

See discussions, stats, and author profiles for this publication at: [Link]

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@[Link] hetpsheth@[Link]
Student, IT Department, D. J. Sanghvi College of Engineering, Vile Parle, Mumbai, India.
Pratik Kanani
pratikkanani123@[Link]
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

[Link] 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 [Link]
remote object that is called. Second one is the Client Start the Server--> python3 [Link]
object which is an object whose method makes a remote Start the Client--> python3 [Link]
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 = [Link](Server)
The extensive number of libraries supporting Python has [Link]("[Link]", url)
made implementing RMI possible in it. The process is The server is named as [Link] 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 = [Link]("PYRONAME:[Link]")
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.

[Link] 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=[Link]()
print('date: '+[Link]('%d-%m-%y')+' Time:
'+[Link]('%H:%M:%S'))
@[Link] 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,
[Link](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 = [Link]()
ns = [Link]()
url = [Link](Server)
[Link]("[Link]", url)
print("The Server is now active., please request your
calculations or start file transfer")
[Link]()

B. Client Code:

import Pyro4
import os
import datetime Fig.4. Running the First Client
Client = [Link]("PYRONAME:[Link]")
name =input("What is your name? ").strip() D. Client-2:
now=[Link]()
print('date: '+[Link]('%d-%m-%y')+' Time:
'+[Link]('%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" +'[Link] \n'+
'[Link] \n'+ '[Link] \n'+ '[Link] \n'+
'[Link] \n')
c=int(input('Enter your choice: '))

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


print([Link](a,b))
elif (c==2):
print([Link](a,b))
elif (c==3):
print([Link](a,b))
elif (c==4):
print([Link](a,b))
elif (c==5):
print([Link](a))
else:
print('invalid input')

[Link] 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] [Link]. (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 [Link]
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:
[Link]
The subprocess package and the os module available Socket-Programming-and-RMI-Using-Simulating-
with Python were also used, through which the files [Link] [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] [Link]. (2017). RMI-IIOP. [online] Available at:
not support Linux, for example, Windows. Thus, [Link] [Accessed 19 Sep.
2017].
future research should focus on transferring files using
[12] [Link]. (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. [Link]
[Link] [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] [Link]. (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 [Link] [Accessed 19 Sep. 2017].
forward and used to make more complex systems in [15] [Link]. (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 [Link]
P_and_UDP_Protocols [Accessed 26 Sep. 2017].
domain cannot be ignored. With the ever increasing
[16] [Link]. (2017). [online] Available at:
community, it is possible that Python may supplant [Link]
Java in the field of Distributed Computing in the [Link] [Accessed 26 Sep. 2017].
coming future.

REFERENCES
[1] [Link]. (2017). Information Skills for a 21st
Century Scotland - Information Literacy: The Importance of.
[online] Available at:
[Link]
importanceof/ [Accessed 9 Sep. 2017].
[2] A. Raju,” Advanced Java”
[3] Anon, (2017). [online] Available at:
[Link]
[Link] [Accessed 20 Sep. 2017].
[4] [Link]. (2017). Remote Procedure Calls (RPC).
[online] Available at:
[Link]
[Accessed 20 Sep. 2017].
[5] [Link]. (2017). Java remote method invocation.
[online] Available at:
[Link]
n [Accessed 20 Sep. 2017].
[6] "Programming Language Trends - O'Reilly Radar".
[Link]. 2 August 2006.

[Link] 37

View publication stats

Common questions

Powered by AI

Python offers several advantages over Java for implementing RMI in distributed computing. First, Python is known for its readability and efficiency, allowing developers to write concise code, which simplifies complex tasks . Python also benefits from a large standard library capable of handling various programming models, which contributes to quicker and more flexible implementation . Furthermore, Python's high-level nature and dynamic typing make it easier to manage, especially when dealing with rapid development environments . While Python generally runs slower than Java because of its interpretation into C, its flexibility and ease of use often compensate for this deficit in speed .

Python's dynamic typing and interpreted nature usually result in slower execution compared to Java, which is statically typed and compiled . However, Python offers greater flexibility, enabling rapid prototyping and development, which can be advantageous in distributed computing by allowing quick adjustments and enhancements to complex systems . The interpreted nature of Python can lead to increased overhead during runtime as it translates into C, but its comprehensive libraries and ease of programming often mitigate these performance issues through increased efficiency in development .

Pyro (Python Remote Objects) simplifies RMI implementations by allowing Python objects to communicate over a network without requiring the manual management of object location or invocation . Pyro automates these tasks by creating proxies for remote objects, thus allowing developers to make remote method calls seamlessly as if they were local method calls . Moreover, Pyro supports cross-platform communication, which enhances the usability of Python in diverse computing environments . It handles the creation and management of client-server communications, thereby reducing the complexity traditionally associated with RMI implementations .

The concept of a Remote Procedure Call (RPC) evolves in object-oriented programming languages like Java and Python by transforming procedural calls into interactions between remote objects, known as Remote Method Invocation (RMI). In Java, RMI leverages the language's inherent object-oriented features to facilitate cross-platform problem-solving and effective resource handling via remote stubs and skeletons . Python further advances this by utilizing libraries such as Pyro, which simplify the creation and management of these objects in network communications, thereby enhancing RPC evolution by adopting an object-oriented model that provides simplified syntax and increased flexibility . These adaptations make remote calls more intuitive and tailored to modern distributed systems, expanding the use of RPC across varied programming environments .

Python might supplant Java in distributed computing because of its increasing popularity in domains such as data science, machine learning, and artificial intelligence, areas where Java has less traction . Python's ease of use, comprehensive libraries, and community support encourage rapid growth in its adoption for distributed systems . Additionally, trends indicate a growing preference for dynamic languages in distributed frameworks that require quick prototyping and interactive programming, benefits that Python readily offers . As Python's ecosystem continues to expand, its integration capabilities and platform versatility position it well to potentially dominate over Java in distributed applications in the future .

Socket programming is essential in RMI systems as it establishes the communication link between the client and server over a network. It does so by using sockets, which are endpoints for sending and receiving data across the network . The two primary types of sockets are TCP (used for connection-oriented transmissions) and UDP (used for connectionless transmissions), both of which provide unique connections for data exchange between multiple clients on the same port . However, traditional socket programming has limitations, such as raw data transfer and security issues, which RMI overcomes by abstracting these details and providing a higher level of communication through remote object method invocation .

In Python RMI using the Pyro library, the main components are the server, client, Pyro daemon, and naming service. The server hosts the remote objects whose methods will be called remotely. The Pyro daemon acts as a middle-man that registers these server objects for accessibility over the network . The naming service facilitates object location for clients by associating URLs with remote object identifiers . Clients interact with these objects using proxies, which make the remote method calls appear local. The seamless integration of these components ensures meaningful interaction between client and server in distributed systems .

TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are two fundamental socket types used in RMI implementations. TCP is connection-oriented, ensuring reliable data transmission with error correction and flow control features. It is suited for applications requiring guaranteed data delivery, such as file transfers in RMI systems . UDP, conversely, is a connectionless protocol that offers faster data transmission by forgoing these reliability checks, making it suitable for real-time applications where speed is prioritized over packet loss . In distributed systems, the choice between TCP and UDP affects system robustness, with TCP providing reliability and UDP offering speed, influencing the design of communication protocols within RMI frameworks .

Pyro4 significantly reduces the programming effort required for RMI in Python by automating many of the intricate tasks associated with network communications and remote object management. It allows developers to focus on application logic rather than low-level networking details. Pyro4 manages object registration, location, and connection processes seamlessly, permitting normal Python calls for remote method invocation . Additionally, Pyro4 integrates well with Python's flexible programming paradigms, supporting diverse project needs while bolstering the ease of creating distributed applications without extensive boilerplate code .

Implementing RMI in Python for file transfers presents challenges such as the integration of system-dependent commands which complicate cross-platform compatibility, evident when certain Python modules rely on Linux commands for file transfers . Moreover, the difficulty of transporting large files efficiently over networked systems is a hurdle. Future research could focus on developing cross-platform libraries or enhancing existing ones like Pyro, to support efficient file transfer protocols that do not depend on specific operating systems, thereby ensuring broader compatibility and functionality .

You might also like