def __init__(self, port, serverFamily="default"): super().__init__(prompt=self.STD_PROMPT) self._protocolId = 0 self._selected = None self._protocols = {} switchobjectHandler = Command("switch", "Switch object to control", self._switchObjectCommand) sendcommandHandler = Command("send", "Send command to object", self._sendCommand) listobjectsHandler = Command("list", "list current connections", self._listCommand) reprogramHandler = Command("reprogram", "reprogram bot. Careful. Don't BRICK it.", self._reprogramCommand) downloadBrainHandler = Command( "download_brain", "download the bot's current brain as a tar ball.", self._downloadBrainCommand) self.registerCommand(switchobjectHandler) self.registerCommand(sendcommandHandler) self.registerCommand(listobjectsHandler) self.registerCommand(reprogramHandler) self.registerCommand(downloadBrainHandler) coro = playground.create_server(lambda: RemoteControlProtocol(self), port=port, family=serverFamily) asyncio.ensure_future(coro)
def main(): loop = asyncio.get_event_loop() coro = playground.create_server(EchoServerProtocol,'localhost', 2001) server = loop.run_until_complete(coro) try: loop.run_forever() except KeyboardInterrupt: pass server.close() loop.run_until_complete(server.wait_close()) loop.close()
def main(args): loop = asyncio.get_event_loop() coro = playground.create_server(ServerProtocol, "localhost", PORT_NUM) server = loop.run_until_complete(coro) printx('Servering on{}'.format(server.sockets[0].getsockname())) # loop.set_debug(1) try: loop.run_forever() except KeyboardInterrupt: pass server.close() loop.run_until_complete(server.wait_closed()) loop.close()
def main(): loop = asyncio.get_event_loop() loop.set_debug(enabled=True) from playground.common.logging import EnablePresetLogging, PRESET_DEBUG EnablePresetLogging(PRESET_DEBUG) coro = playground.create_server(EchoServerProtocol, 'localhost', 2001) server = loop.run_until_complete(coro) try: loop.run_forever() except KeyboardInterrupt: pass server.close() loop.run_until_complete(server.wait_close()) loop.close()
def main(argv): port = int(argv[1]) if len(argv) >= 2 else 8888 loop = asyncio.get_event_loop() # coro = loop.create_server(EscapeServer, '', port) coro = playground.create_server(EscapeServer, '20191.2.5.2554', port) server = loop.run_until_complete(coro) try: loop.run_forever() except KeyboardInterrupt: pass server.close() loop.run_until_complete(server.wait_closed()) loop.close()
def main(args): username = '******' password = '******' bank_client = BankClientProtocol(bank_cert, username, password) loop = asyncio.get_event_loop() coro = playground.create_server(lambda: Ex8Server(bank_client), 'localhost', SERVER_PORT) server = loop.run_until_complete(coro) try: loop.run_forever() except KeyboardInterrupt: pass server.close() loop.run_until_complete(server.wait_close()) loop.close()
def __init__(self, port, serverFamily="default"): super().__init__(prompt=self.STD_PROMPT) # Each object (bot) needs a protocol instance to connect to the C&C. # _protocols is a dict where the key is the _protocolId, and the value is the protocol (RemoteControlProtocol). # _selected is used to identify which object is currently selected. # A protocolId will be assigned to self._selected. # Therefore, you can get the protocol for current selected object by self._protocols.get(self._selected, None). self._protocolId = 0 self._selected = None self._protocols = {} switchobjectHandler = Command("switch", "Switch object to control", self._switchObjectCommand) sendcommandHandler = Command("send", "Send command to object", self._sendCommand) listobjectsHandler = Command("list", "list current connections", self._listCommand) reprogramHandler = Command("reprogram", "reprogram bot. Careful. Don't BRICK it.", self._reprogramCommand) downloadBrainHandler= Command("download_brain", "download the bot's current brain as a tar ball.", self._downloadBrainCommand) # All cmdHandlers need to be registered # so that the shell knows which handler to call when the user inputs a command. # For more information, see playground.common.io.ui.CLIShell. self.registerCommand(switchobjectHandler) self.registerCommand(sendcommandHandler) self.registerCommand(listobjectsHandler) self.registerCommand(reprogramHandler) self.registerCommand(downloadBrainHandler) # When creating the shell, a playground server using RemoteControlProtocol will be created. # The default port is 10013 and you can specify the protocol stack (default, peep, pls). coro = playground.create_server(lambda: RemoteControlProtocol(self), port=port, family=serverFamily) asyncio.ensure_future(coro)
#self.transport.write(self.homepage.welcome_narratives().encode()) def data_received(self, data): if self.homepage.getSign() == False: self.transport.write(self.homepage.welcome_narratives().encode()) self.homepage.setSign() else: string = data.decode() string = string[:-1] output = self.homepage.input(string) self.transport.write(output.encode()) loop = asyncio.get_event_loop() # Each client connection will create a new protocol instance coro = playground.create_server(HomepageServerProtocol, '20191.157.157.157', 9090) server = loop.run_until_complete(coro) # Serve requests until Ctrl+C is pressed print('Serving on {}') try: loop.run_forever() except KeyboardInterrupt: pass loop.run_until_complete(server.wait_closed())
if "-stack" in echoArgs: stack = echoArgs["-stack"] if not 0 in echoArgs: sys.exit(USAGE) mode = echoArgs[0] loop = asyncio.get_event_loop() loop.set_debug(enabled=True) from playground.common.logging import EnablePresetLogging, PRESET_DEBUG EnablePresetLogging(PRESET_DEBUG) # Can be commented out if mode.lower() == "server": coro = playground.create_server(lambda: EchoServerProtocol(), port=port, family=stack) server = loop.run_until_complete(coro) print("Echo Server Started at {}".format( server.sockets[0].gethostname())) loop.run_forever() loop.close() else: remoteAddress = mode control = EchoControl() coro = playground.create_connection(control.buildProtocol, host=remoteAddress, port=port, family=stack) transport, protocol = loop.run_until_complete(coro)
self.transport.write(packk.__serialize__()) print('Sent game command: ', self.escapestep[self.es_iter]) self.es_iter += 1 continue print('Warning: None of the packet Type fits.') if __name__ == "__main__": if ('server' in sys.argv[1:]) or ('client' in sys.argv[1:]): if ('server' in sys.argv[1:]): loop = asyncio.get_event_loop() #coro = playground.create_server(EchoServer,'20191.100.100.1',1810) coro = playground.create_server( lambda: EchoServer('dhaoshu1', 'dhaoshu1_account', 5), 'localhost', Server_Port_number) asyncio.ensure_future(coro) else: print('The bank client config: ', bank_addr, bank_port, bank_username) yngo = input('If the above message is right, continue? [y/n]: ') if yngo == 'y': loop = asyncio.get_event_loop() coro = playground.create_connection( lambda: EchoClient('dhaoshu1', 'dhaoshu1_account'), '20194.0.0.19000', 19008) asyncio.ensure_future(coro) #client = loop.run_until_complete(coro) else: raise Exception('Not able to process, need reconfig.')
def data_received(self, data): string = data.decode() string = string[:-1] output = self.room.command(string) self.transport.write(output.encode()) status = self.room.status() if status == "dead": self.transport.write(("\r\n" + status).encode()) elif status == "escaped": if string == "open door": self.transport.write(("\r\n" + status).encode()) loop = asyncio.get_event_loop() # Each client connection will create a new protocol instance coro = playground.create_server(EscapeServerClientProtocol, '20191.10.20.30', 62261) server = loop.run_until_complete(coro) # Serve requests until Ctrl+C is pressed print('Serving on {}') try: loop.run_forever() except KeyboardInterrupt: pass loop.run_until_complete(server.wait_closed())
async def main(): loop = asyncio.get_event_loop() server = playground.create_server(lambda: EchoServerProtocol(), "localhost", 3456) await asyncio.wait([server])
self.transport.close() if __name__=="__main__": import sys, argparse #from playground.common.logging import EnablePresetLogging, PRESET_DEBUG #EnablePresetLogging(PRESET_DEBUG) parser = argparse.ArgumentParser() parser.add_argument("account") parser.add_argument("-p", "--port", default=5678) parser.add_argument("--price", default=5) args = parser.parse_args(sys.argv[1:]) global_payment_processor.configure(args.account, int(args.price)) loop = asyncio.get_event_loop() coro = playground.create_server(EscapeRoomServerProtocol, host='20191.2.10.1', port=args.port) server = loop.run_until_complete(coro) # Serve requests until Ctrl+C is pressed print('Serving on {}'.format(server.sockets[0].getsockname())) try: loop.run_forever() except KeyboardInterrupt: pass # Close the server server.close() loop.run_until_complete(server.wait_closed()) loop.close()
asyncio.get_event_loop().stop() else: flush_output(">> ", end='') def flush_output(*args, **kargs): print(*args, **kargs) sys.stdout.flush() async def main(args): loop = asyncio.get_event_loop() game = EscapeRoomGame(output=flush_output) game.create_game(cheat=("--cheat" in args)) game.start() flush_output(">> ", end='') loop.add_reader(sys.stdin, game_next_input, game) await asyncio.wait([asyncio.ensure_future(a) for a in game.agents]) if __name__ == "__main__": loop = asyncio.get_event_loop() coro = playground.create_server(EchoServer, '20191.100.100.1', 1810) #coro = playground.create_server(EchoServer,'localhost',1810) asyncio.ensure_future(coro) #asyncio.ensure_future(main(sys.argv[1:])) #loop.run_forever() try: loop.run_forever() except KeyboardInterrupt: loop.close()
print("S: SUBMITRESPONSE {} {} {}".format(packet.submit_status, packet.client_status, packet.server_status)) elif isinstance(packet, gc_packet_types.GameCommandPacket): command = gc_packet_types.process_game_command(packet) time.sleep(.2) lines = command.split("<EOL>\n") if self.verification: for line in lines: if len(line) > 0: print("Sc: ", line) self.game.command(line) else: raise ValueError(packet.DEFINITION_IDENTIFIER) if __name__ == "__main__": loop = asyncio.get_event_loop() coro = playground.create_server(StudentServer, port=7826) server = loop.run_until_complete(coro) try: loop.run_forever() except KeyboardInterrupt: pass server.close() loop.run_until_complete(server.wait_close()) loop.close()
if switch == 2: game.create_game(roomswitch=switch) game.start() await asyncio.wait([asyncio.ensure_future(a) for a in game.agents]) if switch == 3: game.create_game(roomswitch=switch) game.start() await asyncio.wait([asyncio.ensure_future(a) for a in game.agents]) if __name__ == "__main__": loop = asyncio.get_event_loop() # Each client connection will create a new protocol instance coro = playground.create_server(EchoServerClientProtocol, "localhost", port=8666, family="crap") server = loop.run_until_complete(coro) loop.set_debug(enabled=True) from playground.common.logging import EnablePresetLogging, PRESET_DEBUG EnablePresetLogging(PRESET_DEBUG) # Serve requests until Ctrl+C is pressed print('Serving on {}'.format(server.sockets[0].getsockname())) try: loop.run_forever() except KeyboardInterrupt: pass # Close the server
print(lines) for line in lines: print(line) if line !="": # process each line command = line output = self.game.command(command) else: self.transport.close() if __name__=="__main__": loop = asyncio.get_event_loop() # Each client connection will create a new protocol instance c = playground.create_server(myserver,'localhost',4219) server = loop.run_until_complete(c) # Serve requests until Ctrl+C is pressed #print('Serving on {}'.format(server.sockets[0].getsockname())) try: loop.run_forever() except KeyboardInterrupt: pass # Close the server server.close() loop.run_until_complete(server.wait_closed()) loop.close()
self.homepage = Homepage() #self.transport.write(self.homepage.welcome_narratives().encode()) def data_received(self, data): if self.homepage.getSign() == False: self.transport.write(self.homepage.welcome_narratives().encode()) self.homepage.setSign() else: string = data.decode() string = string[:-1] output = self.homepage.input(string) self.transport.write(output.encode()) loop = asyncio.get_event_loop() # Each client connection will create a new protocol instance coro = playground.create_server(HomepageServerProtocol, '20191.10.20.30', 6261) server = loop.run_until_complete(coro) # Serve requests until Ctrl+C is pressed print('Serving on {}') try: loop.run_forever() except KeyboardInterrupt: pass loop.run_until_complete(server.wait_closed())
self.escapestep[self.es_iter]) print('Sent game command: ', self.escapestep[self.es_iter]) self.transport.write(packk.__serialize__()) self.es_iter += 1 continue print('Warning: None of the packet Type fits.') if __name__ == "__main__": if ('server' in sys.argv[1:]) or ('client' in sys.argv[1:]): if ('server' in sys.argv[1:]): loop = asyncio.get_event_loop() #coro = playground.create_server(EchoServer,'20191.100.100.1',1810) coro = playground.create_server(EchoServer, 'localhost', Server_Port_number) asyncio.ensure_future(coro) else: print('The bank client config: ', bank_addr, bank_port, bank_username) yngo = input('If the above message is right, continue? [y/n]: ') if yngo == 'y': loop = asyncio.get_event_loop() coro = playground.create_connection(EchoClient, '20194.0.0.19000', 19007) asyncio.ensure_future(coro) #client = loop.run_until_complete(coro) else: raise Exception('Not able to process, need reconfig.') try: loop.run_forever()
def data_received(self, data): data = data.decode() command = list(filter(None, data.split("<EOL>\n"))) for commandline in command: print('Data recevied:{!r}'.format(commandline)) self.game.command(commandline) # data_send = self.game.command(command[0]) def data_send(self, data): self.transport.write((data + '<EOL>\n').encode()) print('Data sent:{!r}'.format(data)) async def flyingkey_event(self): await asyncio.wait( [asyncio.ensure_future(a) for a in self.game.agents]) if __name__ == "__main__": loop = asyncio.get_event_loop() coro = playground.create_server(EchoServer, 'localhost', 30000) server = loop.run_until_complete(coro) try: loop.run_forever() except KeyboardInterrupt: pass server.close() loop.run_until_complete(server.wait_close()) loop.close()
await asyncio.wait([asyncio.ensure_future(a) for a in game.agents]) if __name__ == "__main__": if IS_ONLINE: IP = '20194.1.1.200' PORT = "12345" args = [] loop = asyncio.get_event_loop() args.append(loop) username = bank_username password = getpass.getpass("Enter password for {}: ".format(username)) args.append(password) args.append(sys.argv[1:]) coro = playground.create_server(lambda: ServerProtocol(args), host=IP, port=PORT, family=STACK) server = loop.run_until_complete(coro) print('Serving on {}'.format(server.sockets[0].getsockname())) try: loop.run_forever() except KeyboardInterrupt: pass server.close() loop.run_until_complete(server.wait_closed()) loop.close() else: asyncio.ensure_future(main(args=sys.argv[1:])) asyncio.get_event_loop().run_forever()
#from playground.common.logging import EnablePresetLogging, PRESET_DEBUG #EnablePresetLogging(PRESET_DEBUG) parser = argparse.ArgumentParser() parser.add_argument("account") parser.add_argument("-p", "--port", default=5657) parser.add_argument("--price", default = 0) parser.add_argument("-s", "--stack", default = "pls_roast") args = parser.parse_args(sys.argv[1:]) global_payment_processor.configure(args.account, int(args.price)) global_payment_processor.set_src_account(args.account) stack = args.stack loop = asyncio.get_event_loop() coro = playground.create_server(HomepageServerProtocol, host='20191.2.1.0', port=args.port,family = stack) server = loop.run_until_complete(coro) # Serve requests until Ctrl+C is pressed print('Serving on {}'.format(server.sockets[0].getsockname())) try: loop.run_forever() except KeyboardInterrupt: pass # Close the server server.close() loop.run_until_complete(server.wait_closed()) loop.close()
if __name__ == "__main__": import sys, argparse #from playground.common.logging import EnablePresetLogging, PRESET_DEBUG #EnablePresetLogging(PRESET_DEBUG) parser = argparse.ArgumentParser() parser.add_argument("account") parser.add_argument("-p", "--port", default=5678) parser.add_argument("--price", default=5) args = parser.parse_args(sys.argv[1:]) global_payment_processor.configure(args.account, int(args.price)) loop = asyncio.get_event_loop() coro = playground.create_server(EscapeRoomServerProtocol, host='localhost', port=args.port) server = loop.run_until_complete(coro) # Serve requests until Ctrl+C is pressed print('Serving on {}'.format(server.sockets[0].getsockname())) try: loop.run_forever() except KeyboardInterrupt: pass # Close the server server.close() loop.run_until_complete(server.wait_closed()) loop.close()
asyncio.ensure_future(a) def connection_lost(self, ex): print("S: closing transport") self.transport.close() def data_received(self, data): text = data.decode() print("SR: ", text) asyncio.sleep(.2) lines = text.split("<EOL>\n") if self.game.status == "playing": for line in lines: if len(line) > 0: print("S: ", line) self.game.command(line) if __name__ == "__main__": loop = asyncio.get_event_loop() coro = playground.create_server(StudentServer,"localhost", 1290) server = loop.run_until_complete(coro) try: loop.run_forever() except KeyboardInterrupt: pass server.close() loop.run_until_complete(server.wait_close()) loop.close()
# input = input+"<EOL>\n" print("Server sends:" + input) game_packet = GameResponsePacket(res=input, st=str(self.game.status)) game_packet_bytes = game_packet.__serialize__() self.transport.write(game_packet_bytes) time.sleep(0.1) def playGame(self, data): if self.game.status == "playing": output = self.game.command(data) async def gameAgents(self): for a in self.game.agents: asyncio.ensure_future(a) if __name__ == "__main__": # EnablePresetLogging(PRESET_DEBUG) theGame = None loop = asyncio.get_event_loop() coro = playground.create_server(lambda: EchoServer(theGame), server_ip, server_port) server = loop.run_until_complete(coro) print("server started") try: loop.run_forever() except KeyboardInterrupt: pass loop.run_until_complete(server.close()) print("server closed") loop.close()
if switch == 2: game.create_game(roomswitch=switch) game.start() await asyncio.wait([asyncio.ensure_future(a) for a in game.agents]) if switch == 3: game.create_game(roomswitch=switch) game.start() await asyncio.wait([asyncio.ensure_future(a) for a in game.agents]) if __name__ == "__main__": loop = asyncio.get_event_loop() # Each client connection will create a new protocol instance coro = playground.create_server(EchoServerClientProtocol, 'localhost', 8666) server = loop.run_until_complete(coro) loop.set_debug(enabled=True) from playground.common.logging import EnablePresetLogging, PRESET_DEBUG EnablePresetLogging(PRESET_DEBUG) # Serve requests until Ctrl+C is pressed print('Serving on {}'.format(server.sockets[0].getsockname())) try: loop.run_forever() except KeyboardInterrupt: pass # Close the server server.close()
parser.add_argument("--count", default=None) parser.add_argument("--stack", default="default") parser.add_argument("--debug", action="store_true", default=False) args = parser.parse_args(sys.argv[1:]) if args.debug: from playground.common.logging import EnablePresetLogging, PRESET_DEBUG EnablePresetLogging(PRESET_DEBUG) if args.mode == "server": if args.msg != None or args.count != None: print("Can't specify a message or a count for a server") sys.exit(-1) coro = playground.create_server(RawEchoServer, port=201, family=args.stack) asyncio.get_event_loop().run_until_complete(coro) asyncio.get_event_loop().run_forever() else: if args.msg != None and args.count != None: print( "Can specify an explicity message or a byte count, but not both" ) sys.exit(-1) if args.msg != None: data_to_send = args.msg.encode() elif args.count != None: data_to_send = os.urandom(int(int(args.count) / 2)).hex().encode() else: data_to_send = b"This is a test message from an echo client!"