From aaff11808eebd49c11510faefc08db664fa1f6b8 Mon Sep 17 00:00:00 2001 From: Fierelier Date: Tue, 20 Apr 2021 16:35:56 +0200 Subject: [PATCH] Add pipe_to_tcp utility --- fstream-util-pipe_to_tcp.py | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 fstream-util-pipe_to_tcp.py diff --git a/fstream-util-pipe_to_tcp.py b/fstream-util-pipe_to_tcp.py new file mode 100644 index 0000000..1cfbaf4 --- /dev/null +++ b/fstream-util-pipe_to_tcp.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 +import sys + +oldexcepthook = sys.excepthook +def newexcepthook(type,value,traceback): + oldexcepthook(type,value,traceback) + #input("Press ENTER to quit.") +sys.excepthook = newexcepthook + +import os +p = os.path.join +pUp = os.path.dirname +s = False +if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): + s = os.path.realpath(sys.executable) +else: + s = os.path.realpath(__file__) +sp = pUp(s) + +# script start +import socket +import threading +import queue + +serverAddr = ("127.0.0.1",61921) +serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +serverSocket.bind(serverAddr) +serverSocket.listen(1) + +connection = False +connectionLock = threading.Lock() + +class pipeThread(threading.Thread): + def __init__(self): + threading.Thread.__init__(self) + + def run(self): + while True: + data = sys.stdin.buffer.read(1000) + try: + with connectionLock: + connection.send(data) + except Exception as e: + print(e) + +pThread = pipeThread() +pThread.start() + +while True: + conn, address = serverSocket.accept() + with connectionLock: + connection = conn + connection.settimeout(None) \ No newline at end of file