Write two programs (or one program with two modes) which run on networked computers, and send some messages between them.

The protocol used may be language-specific or not, and should be suitable for general distributed programming; that is, the protocol should be generic (not designed just for the particular example application), readily capable of handling the independent communications of many different components of a single application, and the transferring of arbitrary data structures natural for the language.

This task is intended to demonstrate high-level communication facilities beyond just creating sockets.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
import SimpleXMLRPCServer
 
class MyHandlerInstance:
    def echo(self, data):
        '''Method for returning data got from client'''
        return 'Server responded: %s' % data
 
    def div(self, num1, num2):
        '''Method for divide 2 numbers'''
        return num1/num2
 
def foo_function():
    '''A function (not an instance method)'''
    return True
 
HOST = "localhost"
PORT = 8000
 
server = SimpleXMLRPCServer.SimpleXMLRPCServer((HOST, PORT))
 
# register built-in system.* functions.
server.register_introspection_functions()
 
# register our instance
server.register_instance(MyHandlerInstance())
 
# register our function as well
server.register_function(foo_function)
 
try:
    # serve forever
    server.serve_forever()
except KeyboardInterrupt:
    print 'Exiting...'
    server.server_close()