Distributed Computing with XML-RPC in Python

I need to create two Python programs, Server.py and Client.py. Server.py should register x procedures that the client will be able to call. It will then bind to the address “localhost” and port 8000.

Server.py should support the following procedures:

  • “name” returns the name of the server which is passed on the command line 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

  • 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, including handling a divide by zero scenario

For Client.py, the client connects to the server using the server’s address and the port the server is listening on (in this case, localhost and 8000). x and y will equal 8 and 6, and will be then pass on to those different functions listed in Server.py

This is the code I have for both programs:

Server.py

import sys
import time
from xmlrpc.server import SimpleXMLRPCServer

host_address = sys.argv[1]
host_port = sys.argv[2]
server = SimpleXMLRPCServer((str(hostAddress), int(port)))

def add(x, y):
    return x + y

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

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

def div(x, y):
    try:
        return x / y
    except ZeroDivisionError:
        print(x + " divided by " + y + " is infinity.")

def name():
    return hostAddress

def helpFunc():
    return server.system_listMethods()

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

server.register_function(name)
server.register_function(helpFunc)
server.register_function(add)
server.register_function(servertime)
server.register_function(sub)
server.register_function(mult)
server.register_function(div)
server.serve_forever()

Client.py

import xmlrpc.client
import sys
from xmlrpc.server import SimpleXMLRPCServer

host_address = sys.argv[1]
host_port = sys.argv[2]
x = sys.argv[3]
y = sys.argv[4]

URI = "http://" + host_address + ":" + host_port
proxy = xmlrpc.client.ServerProxy(URI)

print('{} + {} is {}'.format(x, y, str(proxy.add(x, y))))
print('{} - {} is {}'.format(x, y, str(proxy.sub(x, y))))
print('{} * {} is {}'.format(x, y, str(proxy.mult(x, y))))
print('{} / {} is {}'.format(x, y, str(proxy.div(x, y))))
print(proxy.name())
print(proxy.helpFunc())
print(proxy.servertime())

When I run the programs, however, I get the following error:

Traceback (most recent call last): File
“C:UsersshaneDocumentsClient.py”, line 13, in
print(‘{} + {} is {}’.format(x, y, str(proxy.add(x, y)))) File “C:UsersshaneAppDataLocalProgramsPythonPython39libxmlrpcclient.py”,
line 1116, in call
return self.__send(self.__name, args) File “C:UsersshaneAppDataLocalProgramsPythonPython39libxmlrpcclient.py”,
line 1456, in __request
response = self.__transport.request( File “C:UsersshaneAppDataLocalProgramsPythonPython39libxmlrpcclient.py”,
line 1160, in request
return self.single_request(host, handler, request_body, verbose) File
“C:UsersshaneAppDataLocalProgramsPythonPython39libxmlrpcclient.py”,
line 1172, in single_request
http_conn = self.send_request(host, handler, request_body, verbose) File
“C:UsersshaneAppDataLocalProgramsPythonPython39libxmlrpcclient.py”,
line 1285, in send_request
self.send_content(connection, request_body) File “C:UsersshaneAppDataLocalProgramsPythonPython39libxmlrpcclient.py”,
line 1315, in send_content
connection.endheaders(request_body) File “C:UsersshaneAppDataLocalProgramsPythonPython39libhttpclient.py”,
line 1250, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked) File
“C:UsersshaneAppDataLocalProgramsPythonPython39libhttpclient.py”,
line 1010, in _send_output
self.send(msg) File “C:UsersshaneAppDataLocalProgramsPythonPython39libhttpclient.py”,
line 950, in send
self.connect() File “C:UsersshaneAppDataLocalProgramsPythonPython39libhttpclient.py”,
line 921, in connect
self.sock = self._create_connection( File “C:UsersshaneAppDataLocalProgramsPythonPython39libsocket.py”,
line 843, in create_connection
raise err File “C:UsersshaneAppDataLocalProgramsPythonPython39libsocket.py”,
line 831, in create_connection
sock.connect(sa) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused
it

Could I please get some help on this?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật