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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!