def listen_on_tcp_port():
host = os.getenv(<EOL>"<STR_LIT>",<EOL>"<STR_LIT:127.0.0.1>").strip().lstrip()<EOL>port = int(os.getenv(<EOL>"<STR_LIT>",<EOL>"<STR_LIT>").strip().lstrip())<EOL>backlog = int(os.getenv(<EOL>"<STR_LIT>",<EOL>"<STR_LIT:5>").strip().lstrip())<EOL>size = int(os.getenv(<EOL>"<STR_LIT>",<EOL>"<STR_LIT>").strip().lstrip())<EOL>sleep_in_seconds = float(os.getenv(<EOL>"<STR_LIT>",<EOL>"<STR_LIT>").strip().lstrip())<EOL>shutdown_hook = os.getenv(<EOL>"<STR_LIT>",<EOL>"<STR_LIT>".format(<EOL>host,<EOL>port)).strip().lstrip()<EOL>if os.path.exists(shutdown_hook):<EOL><INDENT>print(("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>.format(<EOL>shutdown_hook))<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>now = datetime.datetime.now().isoformat()<EOL>print(("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>.format(<EOL>now,<EOL>host,<EOL>port,<EOL>backlog,<EOL>size,<EOL>sleep_in_seconds,<EOL>shutdown_hook))<EOL>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<EOL>s.bind((host, port))<EOL>s.listen(backlog)<EOL>msg = <NUM_LIT:0><EOL>while <NUM_LIT:1>:<EOL><INDENT>client, address = s.accept()<EOL>send_data = False<EOL>data = None<EOL>while not data:<EOL><INDENT>data = client.recv(size)<EOL>if data:<EOL><INDENT>now = datetime.datetime.now().isoformat()<EOL>print(("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>.format(<EOL>now,<EOL>msg,<EOL>data))<EOL>msg += <NUM_LIT:1><EOL>if msg > <NUM_LIT>:<EOL><INDENT>msg = <NUM_LIT:0><EOL><DEDENT>send_data = True<EOL><DEDENT>else:<EOL><INDENT>time.sleep(sleep_in_seconds)<EOL><DEDENT><DEDENT>if send_data:<EOL><INDENT>client.send(data)<EOL><DEDENT>if os.path.exists(shutdown_hook):<EOL><INDENT>now = datetime.datetime.now().isoformat()<EOL>print(("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>.format(<EOL>now,<EOL>shutdown_hook))<EOL><DEDENT>client.close()<EOL><DEDENT>
listen_on_tcp_port

    Run a simple server for processing messages over ``TCP``.

    ``LISTEN_ON_HOST`` - listen on this host ip address

    ``LISTEN_ON_PORT`` - listen on this ``TCP`` port

    ``LISTEN_SIZE`` - listen on to packets of this size

    ``LISTEN_SLEEP`` - sleep this number of seconds per loop

    ``LISTEN_SHUTDOWN_HOOK`` - shutdown if file is found on disk