def setupServer(self,port=55555): self.server = ChatServerFactory(self.idGenerator) self.log('Signal','Setting up the server on port %d' % port,'setupServer') endpoint = TCP4ServerEndpoint(reactor, port) d = endpoint.listen(self.server) d.addErrback(self.errorHandler) self.checkServer()
class ServerWrapper(object): def __init__(self,idGenerator): self.logger = Logger() self.server = '' self.idGenerator = idGenerator def setupServer(self,port=55555): self.server = ChatServerFactory(self.idGenerator) self.log('Signal','Setting up the server on port %d' % port,'setupServer') endpoint = TCP4ServerEndpoint(reactor, port) d = endpoint.listen(self.server) d.addErrback(self.errorHandler) self.checkServer() def errorHandler(self,data): self.server = None self.log('Error','Server: %s -> %s' % (repr(data),data.getErrorMessage()),'errorHandler') def checkServer(self): if self.server == None: raise Exception('Server not set') def sendMessage(self,data,originator): self.log('Signal','Message Sent over network: %s...' % data[0:10],'sendMessage') self.server.sendMessage(data,originator) def registerObserver(self,observer): self.server.registerObserver(observer) def log(self,level,data,method=''): self.logger.log(level,data,method,'ServerWrapper')