def main(): # Parse the input aruments ap = argparse.ArgumentParser() ap.add_argument("--address", "-a", required=False, default="0.0.0.0", help="listening IP address, default=\"0.0.0.0\"") ap.add_argument("--port", "-p", required=False, default=9910, help="listening UDP Port, default=9910") ap.add_argument("--config", required=False, default="default_config.xml", help="config XML file from ATEM software (default=default_config.xml)") ap.add_argument("--debug", "-d", required=False, default="INFO", help="debug level (in quotes): NONE, INFO (default), WARNING, DEBUG") args = ap.parse_args() host = args.address port = args.port config_file = args.config print("ATEM Server Starting...") s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind((host, port)) client_mgr = ClientManager() atem_config.config_init(config_file) print("ATEM Server Running...Hit ctrl-c to exit") while True: try: # Process incoming packets but timeout after a while so the clients # can perform cleanup and resend unresponded packets. readers, writers, errors = select.select([s], [], [], 0.050) if len(readers) > 0: try: bytes, addr = s.recvfrom(2048) packet = Packet(addr, bytes) packet.parse_packet() client = client_mgr.get_client(packet.ip_and_port, packet.session_id) client.process_inbound_packet(packet) except ConnectionResetError: print("connection reset!") s.close() s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind((host, port)) continue except KeyboardInterrupt: raise # Perform regularly regardless of incoming packets client_mgr.run_clients(s) except KeyboardInterrupt: # quit sys.exit()