From 0c025cbf7f8a80c1a3caa9099d541c53ac3ec8fd Mon Sep 17 00:00:00 2001 From: Fierelier Date: Wed, 21 Apr 2021 12:57:19 +0200 Subject: [PATCH] Status messages for util-pipe_to_tcp --- fstream-util-pipe_to_tcp.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/fstream-util-pipe_to_tcp.py b/fstream-util-pipe_to_tcp.py index 0fb6e14..f10ca22 100644 --- a/fstream-util-pipe_to_tcp.py +++ b/fstream-util-pipe_to_tcp.py @@ -22,8 +22,11 @@ import socket import threading import queue +def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) + serverAddr = ("127.0.0.1",61921) serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +eprint("Opening socket...") serverSocket.bind(serverAddr) serverSocket.listen(1) @@ -35,23 +38,31 @@ class pipeThread(threading.Thread): threading.Thread.__init__(self) def run(self): + global connection while True: data = sys.stdin.buffer.read(1000) - try: - with connectionLock: - connection.send(data) - except Exception as e: - print(e) + + with connectionLock: + try: + if type(connection) != bool: + connection.send(data) + except Exception as e: + connection = False + print(e) pThread = pipeThread() pThread.start() while True: + eprint("Awaiting connection...") conn, address = serverSocket.accept() + eprint("Connection established, sending data.") with connectionLock: try: - connection.close() + if type(connection) != bool: + connection.close() except Exception as e: print(e) + connection = conn connection.settimeout(15) \ No newline at end of file