| 41 | return (self.service is not None) |
| 42 | |
| 43 | def handleRequest(self, msg): # msg is a json object |
| 44 | method = msg.get("method") |
| 45 | seqNum = msg.get("seqNum", 0) |
| 46 | # print("handle message: ", str(id(self)), method, seqNum) |
| 47 | service = self.service |
| 48 | if service: |
| 49 | # let the text service handle the message |
| 50 | reply = service.handleRequest(msg) |
| 51 | else: # the text service is not yet initialized |
| 52 | reply = {"seqNum": seqNum} |
| 53 | success = False |
| 54 | if method == "init": # initialize the text service |
| 55 | success = self.init(msg) |
| 56 | reply["success"] = success |
| 57 | # print(reply) |
| 58 | return reply |
| 59 | |
| 60 | |
| 61 | class Server(object): |