global textPreRequest def textPreRequest(event,self,requestLength): if requestLength <= 128: return sendResponse(self.connection,"error: too long".encode("utf-8")) self.closeThread() return True addEventHandler("onPreRequest",textPreRequest) global textRequest def textRequest(event,self,requestLength): data = self.connection.recv(requestLength) sendResponse(self.connection,data) text = data.decode("utf-8") print(":".join(map(str,self.address))+ " > " +text) if text == "exit": with threadsLock: global close close = True self.closeThread() return True addEventHandler("onRequest",textRequest)