# return False def handle_accept(self): soc, addr = self.accept() self.onClientAccepeted(soc, addr) def stop(self): map(ClientPort.stop, self.client_ports) def client_logout(self, client_port): self.client_ports.remove(client_port) def onClientAccepeted(self, client_soc, client_addr): log("Server clientAccepted", client_soc) client_port = ClientPort(client_soc, \ logout_listener = self.client_logout) self.client_ports.append(client_port) socthread = HellocConnection(client_soc, client_port.handle_message, \ soc_closed=client_port.handle_soc_closed) client_port.set_socthread(socthread) def run(self): asyncore.loop(timeout=LOOP_TIMEOUT) if __name__ == "__main__": server = HellocServer() ExitHandler.setup() ExitHandler.registerExitHandler(server.stop) server.run()
# return False def handle_accept(self): soc, addr = self.accept() self.onClientAccepeted(soc, addr) def stop(self): map(ClientPort.stop, self.client_ports) def client_logout(self, client_port): self.client_ports.remove(client_port) def onClientAccepeted(self, client_soc, client_addr): log("Server clientAccepted", client_soc) client_port = ClientPort(client_soc, \ logout_listener = self.client_logout) self.client_ports.append(client_port) socthread = HellocConnection(client_soc, client_port.handle_message, \ soc_closed=client_port.handle_soc_closed) client_port.set_socthread(socthread) def run(self): asyncore.loop(timeout=LOOP_TIMEOUT) if __name__ == "__main__": server = HellocServer() ExitHandler.setup(); ExitHandler.registerExitHandler(server.stop) server.run()
if FileMessage.isfile(msg): FileMessage(msg).save() pass def start(self, username, password): self.soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.soc.connect((self.server, self.port)) log("client started") self.socthread = HellocConnection(self.soc, self.handle_message) self.login(username, password) self.get_friends() def stop(self): log("Client stop") self.socthread.stop() if __name__ == "__main__": args = sys.argv username = len(args) > 1 and args[1] or "user1" password = len(args) > 2 and args[2] or "helloc" ExitHandler.setup() client = HellocClient(LOCAL_HOST, PORT) ExitHandler.registerExitHandler(client.stop) client.start(username, password) if 1: #len(args) > 1: # threading.Timer(5.0, client.stop).start() client.send_chat(2, data="Hello, I am python client") #client.send_file(1, normpath("../../test-data/WelcomeScan.jpg")) asyncore.loop(timeout=LOOP_TIMEOUT)
if FileMessage.isfile(msg): FileMessage(msg).save() pass def start (self, username, password): self.soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.soc.connect((self.server, self.port)) log("client started") self.socthread = HellocConnection(self.soc, self.handle_message) self.login(username, password) self.get_friends() def stop(self): log("Client stop") self.socthread.stop() if __name__ == "__main__": args = sys.argv username = len(args) > 1 and args[1] or "user1" password = len(args) > 2 and args[2] or "helloc" ExitHandler.setup() client = HellocClient(LOCAL_HOST, PORT) ExitHandler.registerExitHandler(client.stop) client.start(username, password) if 1 : #len(args) > 1: # threading.Timer(5.0, client.stop).start() client.send_chat(2, data="Hello, I am python client") #client.send_file(1, normpath("../../test-data/WelcomeScan.jpg")) asyncore.loop(timeout = LOOP_TIMEOUT)