Can someone give a code snippet on how to 'chat' using the XMLRPC library in Python? Here's my server code:
from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler
import os
from os import access, path
PATH = 'chatlog.$'
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)
server = SimpleXMLRPCServer(("localhost", 8000),
requestHandler=RequestHandler)
server.register_introspection_functions()
server.register_function(pow)
def chat_function(self):
return (self)
server.register_function(chat_function, 'chat')
def chat_store(self):
to_write = self
if path.exists(PATH):
chat_st2 = open(PATH,'w')
history = chat_st2
chat_st2.seek(0)
chat_st2.write(str(to_write))
chat_st2.close()
chat_st2 = open(PATH,'r')
print (chat_st2)
else:
open(PATH,'w')
chat_st2 = open(PATH,'w')
chat_st2.write(str(to_write))
chat_st2.close()
server.register_function(chat_store, 'store')
print ('Starting your XMLRPC Server...')
print ('Press Ctrl+C to exit')
server.serve_forever()
if KeyboardInterrupt:
exit()
But for some reason it keeps getting errors.