0

I'm trying to build a client and a server using xmlrpc in python, I HAVE to use a class named FunctionWrapper which has a method and the client use it, the method's name is sendMessage_wrapper(self, message), and the server is declared in another class, I'm trying to register the method in the server but when i call the method from de client I raise and error, can you help me, please?

Cliente:

#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import xmlrpclib
from SimpleXMLRPCServer import SimpleXMLRPCServer

from os import path
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
from Constants.Constants import *

class MyApiClient:
    def __init__(self, contact_port = DEFAULT_PORT,contact_ip=LOCALHOST_CLIENT):
        self.contact_port = contact_port
        self.contact_ip = contact_ip
        self.proxy = xmlrpclib.ServerProxy(contact_ip+str(self.contact_port)+"/")


    def sendMessage(self,message):
        self.proxy.sendMessage_wrapper(message)

a = MyApiClient()
a.sendMessage("Hi")
a.sendMessage("WORKING")

Server:

#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import xmlrpclib
from SimpleXMLRPCServer import SimpleXMLRPCServer

from os import path
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
from Constants.Constants import *

class MyApiServer:
    def __init__(self,wrapper, my_port = DEFAULT_PORT):
        self.port = my_port
        self.server = SimpleXMLRPCServer((LOCALHOST,self.port))
        self.wrapper = wrapper
        self.server.register_instance(self.wrapper)
        print("Running")
        self.server.serve_forever()


class FunctionWrapper:
    def __init__(self):
        self.message = None

    """
    Procedimiento que ofrece nuestro servidor, este metodo sera llamado
    por el cliente con el que estamos hablando, debe de
    hacer lo necesario para mostrar el texto en nuestra pantalla.
    """
    def sendMessage_wrapper(self, message):
        self.message = message
        self.showMessage()
    def showMessage(self):
        print ("Mensaje "+self.message)
        #raise  NotImplementedError( "Should have implemented this" )


a = FunctionWrapper()
b = MyApiServer(a)

1 Answers1

0

Here are the constants in case you need it

#! /usr/bin/env python
# -*- coding: utf-8 -*-

#Nombres para etiquetas login local y remoto
MY_PORT_NUMBER_TITLE = "Cual es mi puerto?"
OTHER_PORT_NUMBER_TITLE = "Cual es el puerto de contacto?"
OTHER_IP_NUMBER_TITLE = "Cual es la direccion ip de contacto?"
LOGIN_TITLE = "Acceder"

#Nombres para las etiquetas del chat
CONVERSATION_TITLE = "Conversacion"
SEND_TITLE = "Responder"

#Titulo de las ventans GUI
LOGIN_WINDOW = "Login"
CHAT_WINDOW = "Chat"

#Modos de acceso  al chat, local o remoto
LOCAL = "Local"
REMOTE = "Remote"

#Mensajes de error
WARNING = "¡Alerta!"
MISSING_MESSAGE = "No hay ningun mensaje para enviar"

#Localhost
LOCALHOST = "localhost"
DEFAULT_PORT = 5000
LOCALHOST_CLIENT = "http://localhost:"
  • I solve it using in client self.proxy = xmlrpclib.ServerProxy(contact_ip+str(self.contact_port)+"/", allow_none=True) this in the server: self.server = SimpleXMLRPCServer((LOCALHOST,self.port),allow_none=True) – Daniela Velásquez Garzón Aug 17 '16 at 03:21