def setupClient(self,host='localhost',port=55555):

        self.client = ChatClientFactory()

        endpoint = TCP4ClientEndpoint(reactor, host, port)
        d = endpoint.connect(self.client)
        d.addErrback(self.errorHandler)

        self.checkClient()
class ClientWrapper(object):

    def __init__(self):
        self.logger = Logger()
        self.client = ''

    def setupClient(self,host='localhost',port=55555):

        self.client = ChatClientFactory()

        endpoint = TCP4ClientEndpoint(reactor, host, port)
        d = endpoint.connect(self.client)
        d.addErrback(self.errorHandler)

        self.checkClient()

    def errorHandler(self,data):
        self.client = None
        self.log('Error','%s -> %s' % (repr(data),data.getErrorMessage()),'errorHandler')

    def checkClient(self):

        if self.client == None:
            raise Exception('Client not set')

    def sendMessage(self,data):

        self.log('Signal','Message Sent over network: %s...' % data[0:10],'sendMessage')

        self.client.sendMessage(data)

    def registerObserver(self,observer):
        self.client.registerObserver(observer)

    def log(self,level,data,method=''):
        self.logger.log(level,data,method,'ClientWrapper')