Question

I am doing an assignment for a class and need a little help trying to understand...

I am doing an assignment for a class and need a little help trying to understand how to get started on this assignment. This is needing to be program in python and any help is greatly appreciated.

Distributed Computing with XML-RPC

Description

Common tasks in distributed computing applications often require the ability of one computer to be able to remotely invoke a procedure on another computer in the distributed system. This assignment introduces this idea further using XML-RPC and Python.

XML-RPC is a protocol used to call procedures, (i.e. methods or functions) by one computer (client) on another computer (server). Its name results from fact that XML is used to encode the procedure calls. The means used to transport the XML from the client to the server is HTTP. While Python has built-in support for this functionality, it is important to note that support is not limited to Python but extends to most high level languagesadd. This is inherent in the design since the encoding is generic XML and transport is HTTP.

Finally, there are many ways to implement such functionality. For Python, while outside the scope of this course, the interested reader should explore projects such as Pyro, RPyC, and Fabric.

XML-RPC's implementation in Python is found in the xmlrpc package. In this package, the required modules are xmlrpc.client and xmlrpc.server.

Assignment

This assignment requires you to develop two Python programs. One is a client, the other is the server.

Server

The server should "register" x procedures that the client will be able to call. It will then bind to the address "localhost" and port 8000. This is the address and port that the server will listen to for requests. Note that if you have binding errors, you may use another port as your computer may have an application that is using 8000. Most of the time, however, this will work. Your server invocation must be in the following form:

python server.py localhost 8000

These procedures to be supported are as follows:

name - returns the name of the server which is passed on the commandline during server invocation

help - returns a list of procedures that the server supports

servertime - returns the current time at the server in 24 hour format. I.e. 13:00:01

add(x,y) - returns the sum of x and y

sub(x,y) - returns x - y

mult(x,y) - returns x * y

div(x,y) - returns x/y (be sure to handle the divid by 0 scenario)

Client

The client is to connect to the server using the server's address and the port that the server is listening on (see above). It then will exercise each of the supported procedures using the values 8 and 6 for the values x and y respectively. Your client invocation must be in the following form:

python client.py host_address host_port 8 6

where host_address and host_port are the address and port that the server is listening on. If you are using a single computer for server and client computers just use "localhost" for the address and the port used above. The 8 and the 6 are the values for x and y.

Example Output Of Client:

8 * 6 is 48.0

8 / 6 is 1.3333333333333333

8 + 6 is 14.0

8 - 6 is 2.0

8 / 0 is Infinity

13:50:22

1 0
Add a comment Improve this question Transcribed image text
Answer #1

Server.py

#importing sys module

#importing time module

#importing xmlrpc module

import sys                                                    
import time                                               
from xmlrpc.server import SimpleXMLRPCServer                 

#sys.argv returns a list of command-line arguments as strings
argumentlist = sys.argv 

#storing 1st argument ie hostname. 0th argument would be filename                          
host_address = argumentlist[1]    
  
#storing 2nd argument ie port no             
port = argumentlist[2]                           


#SimpleXMLRPCServer class create a new server instance 
server = SimpleXMLRPCServer((host_address,int(port)))  

 
#methods you want to implement at server side
def addition(x,y):
    return x + y

def subtraction(x,y):
    return x - y

def multiplication(x,y):
    return x * y

def division(x,y):
    try:
         return x/y
    except:
        return "Infinity"

def name():
    return host_address

def help():
    return server.system_listMethods()

def servertime():
    return time.strftime('%H:%M:%S')


#server.register_function(function=None,name=None) register a function that can respond to XML-RPC requests
#params
# function parameter is name of the you implemented at server side
# name  parameter is name that you want to give to the function
#

server.register_function(addition, "add")
server.register_function(subtraction, "sub")
server.register_function(multiplication, "mul")
server.register_function(division, "div")
server.register_function(name, "name")
server.register_function(help, "help")
server.register_function(servertime, "servertime")

#run the server's main loop which means server is continuosly running and listening to requests
server.serve_forever()

exectuion command of server program at terminal: python Server.py localhost 8000

Client.py:

#importing xmlrpc module
#importing sys module

import xmlrpc.client                          
import sys                                   

argumentslist = sys.argv            #sys.argv returns a list of command-line arguments

host_address = argumentslist[1]     #storing 1st argument ie hostname. 0th argument would be filename

host_port = argumentslist[2]        #storing 2nd argument ie port no

uri = "http://"+host_address+":"+host_port   
  
num1 = int(argumentslist[3])     #storing 3 argument which is a first num that we will pass to method
num2 = int(argumentslist[4])     #storing 3 argument which is a first num that we will pass to method

proxy = xmlrpc.client.ServerProxy(uri)  #returns a server proxy object with which we can call methods

#methods that client will call
print('{} + {} is {}'.format(num1,num2,proxy.add(num1, num2)))
print('{} - {} is {}'.format(num1,num2,proxy.sub(num1, num2)))
print('{} * {} is {}'.format(num1,num2,proxy.mul(num1, num2)))
print('{} / {} is {}'.format(num1,num2,proxy.div(num1, num2)))
print(proxy.name())           #returns server's name
print(proxy.help())           #returns list of available methods at server
print(proxy.servertime())     #returns server's time in 24hrs format

client output:

Local x Terminal Local (2) + (venv) C:\Users\ml 04 927 9\PycharmProjects\BST>python Client.py localhost 8000 8 6 8 6 is 14 8

Add a comment
Know the answer?
Add Answer to:
I am doing an assignment for a class and need a little help trying to understand...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • DISTRIBUTED COMPUTING WITH XML-RPC Description Common tasks in distributed computing applications often require the ability of...

    DISTRIBUTED COMPUTING WITH XML-RPC Description Common tasks in distributed computing applications often require the ability of one computer to be able to remotely invoke a procedure on another computer in the distributed system. This assignment introduces this idea further using XML-RPC and Python. XML-RPC is a protocol used to call procedures, (i.e. methods or functions) by one computer (client) on another computer (server). Its name results from fact that XML is used to encode the procedure calls. The means used...

  • I need help with this assignment, please; Programming Assignment 3: UDP Pinger Lab In this lab,...

    I need help with this assignment, please; Programming Assignment 3: UDP Pinger Lab In this lab, you will study a simple Internet ping server written in the Java language, and implement a corresponding client. The functionality provided by these programs is similar to the standard ping programs available in modern operating systems, except that they use UDP rather than Internet Control Message Protocol (ICMP) to communicate with each other. (Java does not provide a straightforward means to interact with ICMP.)...

  • 1. Which of the following protocols is used by a client to send an email message?...

    1. Which of the following protocols is used by a client to send an email message? a. HTTP SMTP b. FTP d. RDP 2. What is the most common network topology today? a/Star c. Hub Ring d. Mesh 3. A client/server network is the simplest network model. a/ True O False 4. Which client server application allows an administrator to control a remote computer, but does not encrypt or secure the communication between client and server? A Telnet C. Remote...

  • Part - Web Server Setup and Demonstration (AJ Objective The objective of this assignment is to...

    Part - Web Server Setup and Demonstration (AJ Objective The objective of this assignment is to some HTTP as application layer protocol and TCP as reliable transport layer protocol HTTP is carried by TCP. Also, in the assignment you will investigate the working of client-server mechanism from both application and networking perspective There are several different ways to setup an HTTP server, including through Apache Tomcat, Apache Glassfish that integrales in an IDE such as Eclipse/NetBeans or even a browser...

  • *****Can someone please HELP me with this assignment please, I am struggling with this assignment and...

    *****Can someone please HELP me with this assignment please, I am struggling with this assignment and would appreciate some help, needs to be done in c/c++ ******* (100 marks) In this problem, you will write a file transfer program for transferring files between two computers connected by a network. The protocol that you will implement is called the Simple File Transfer Protocol (SFTP). The complete description for SFTP is given below. PART 1 SFTP is a simple protocol for transferring...

  • The way I understand it is i'm trying to link a list that I read into...

    The way I understand it is i'm trying to link a list that I read into python from a cvs file to json and xml and pass the doctest. Please refere the lines where I show what I did below. home / study / engineering / computer science / questions and answers / """this script converts a csv file with headers ... Question: """This script converts a CSV file with headers to... Bookmark """This script converts a CSV file with...

  • I NEED HELP WITH NETWORKS ( 1 - 11) QUESTIONS , ENSURE YOU ANSWER THEM ALL...

    I NEED HELP WITH NETWORKS ( 1 - 11) QUESTIONS , ENSURE YOU ANSWER THEM ALL QUESTION 1 Which of the following could be valid DNS resource record entries? (mysite.com, 125.245.206.3, NS) (ibm.com, backup6.ibm.com, CNAME) (158.223.21.2, mypage.edu, A) All of the above None of the above 1 points    QUESTION 2 Which mail protocol keeps state information across sessions? SMTP POP3 IMAP All of the above None of the above 1 points    QUESTION 3 What type of message is...

  • Hi I need some help in C programing class and I doing one of the exercise...

    Hi I need some help in C programing class and I doing one of the exercise so that I can get better at coding. Suppose you are asked to design a software that helps an elementary school student learn multiplication and division of one-digit integer numbers. The software allows the student to select the arithmetic operation she or he wishes to study. The student chooses from a menu one of two arithmetic operations: 1) Multiplication and 2) Division (quotient). Based...

  • I NEED HELP WITH COMPUTER NETWORKS( PLEASE ANSWER THEM ALL) CALCULATIONS & MCQS 1. Name 1...

    I NEED HELP WITH COMPUTER NETWORKS( PLEASE ANSWER THEM ALL) CALCULATIONS & MCQS 1. Name 1 languages that the browser is willing to accept in the following message? GET /kurose_ross/interactive/quotation7.htm HTTP/1.1 Host: gaia.cs.umass.edu Accept: text/plain, text/html, image/gif, image/jpeg, audio/mpeg, audio/basic, video/wmv, video/mp4, application/*, */* Accept-Language: en, fr, de, ar, cs If-Modified-Since: Mon, 12 Aug 2019 07:13:47 -0700 User Agent: Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko/20100101 Firefox/11.0 2. A file of size F = 8 Gbits needs to be distributed to10...

  • on calculations can i see how did the expect come to the solution ,all the workout...

    on calculations can i see how did the expect come to the solution ,all the workout should be included QUESTION 1 A file of size F = 8 Gbits needs to be distributed to10 peers. Suppose the server has an upload rate of u = 68 Mbps, and that the 10 peers have upload rates of: u1 = 20 Mbps, u2 = 22 Mbps, u3 = 12 Mbps, u4 = 19 Mbps, u5 = 25 Mbps, u6 = 24 Mbps,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT