Add option to terminate TCP connections after some time
This commit is contained in:
parent
8c5689171c
commit
e3e55e031e
1 changed files with 247 additions and 240 deletions
11
clippy.py
11
clippy.py
|
|
@ -146,7 +146,8 @@ if __name__ == '__main__':
|
|||
parser.add_argument('-p', '--pixelflut', type=str)
|
||||
parser.add_argument('-t', '--terminal', action='store_true')
|
||||
parser.add_argument('-x', '--termsize', type=str)
|
||||
parser.add_argument('-s', '--socket', action='store_true')
|
||||
parser.add_argument('-s', '--socket', action='store_true', help='Listen on TCP socket (telnet-compatible)')
|
||||
parser.add_argument('-k', '--kill-after', type=int, default=60, help='Kill TCP connections after {kill_after} seconds')
|
||||
parser.add_argument('-n', '--nosleep', action='store_true')
|
||||
parser.add_argument('-b', '--bind', type=str, default='0.0.0.0:2342')
|
||||
parser.add_argument('action', default='Greeting', nargs='?')
|
||||
|
|
@ -246,11 +247,17 @@ if __name__ == '__main__':
|
|||
class ClippyRequestHandler(socketserver.BaseRequestHandler):
|
||||
def handle(self):
|
||||
with contextlib.suppress(BrokenPipeError):
|
||||
start = time.time()
|
||||
srcaddr, srcport = self.client_address
|
||||
print(f'Connection from {srcaddr}:{srcport}')
|
||||
|
||||
agent = random.choice(agents)
|
||||
while True:
|
||||
action = random.choice(agent.animations)
|
||||
print('[\033[38;5;245m{}\033[0m] Playing: {}'.format(self.client_address[0], action), flush=True)
|
||||
#print('[\033[38;5;245m{}\033[0m] Playing: {}'.format(self.client_address[0], action), flush=True)
|
||||
for _img_pf, _img_dsp, img_term in agent(action):
|
||||
if time.time() - start > args.kill_after:
|
||||
return
|
||||
self.request.sendall(b'\033[H'+img_term.encode())
|
||||
host, port = args.bind.split(':')
|
||||
port = int(port)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue