Question
In python, build a simple distributed service by using pickling and networks. Use TCP to coordinate between a host and a server. The host will
In python, build a simple distributed service by using pickling and networks.
Use TCP to coordinate between a host and a server. The host will send a pickled object
and the python source to the server. The server will run the python source with the pickle and
return the results. One server, and its program should add two numbers together and return them.
The object that gets pickled should have a result entry.
The application the server runs should have a run method and send its pickled output (after
invoking run) to stdout (sys.stdout).
1 use sys.argv to get the name of the pickled input.
2 unpickle it.
3 invoke the objects run method
4 pickle it to sys.stdout.
(There is a reason for this.)
Youll need to manually start both the host and server. (a full package like MPI has a
method to start and synchronize servers.) Use localhost (127.0.0.1) for the IP address. It may
be convenient to use two ports and make both host and server a tcp client and a tcp server.
Host
Create the link to the server. Create an instance of the data object, pickle it and send it
to the server along with the python code needed to run the calculation. Wait for a reply.
Unpickle the reply and print the result.
Server
Listen for the hosts message. Receive both the pickled object and the python code - write
them as files. Invoke the python code with the pickled file as a command line argument.
Invoke the python code (HINT use the subprocess package and subprocess.check output
method to do this.) Return the pickled output to the host.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started