Status messages for util-pipe_to_tcp

This commit is contained in:
Fierelier 2021-04-21 12:57:19 +02:00
parent a377f8f584
commit 0c025cbf7f

View File

@ -22,8 +22,11 @@ import socket
import threading import threading
import queue import queue
def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)
serverAddr = ("127.0.0.1",61921) serverAddr = ("127.0.0.1",61921)
serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
eprint("Opening socket...")
serverSocket.bind(serverAddr) serverSocket.bind(serverAddr)
serverSocket.listen(1) serverSocket.listen(1)
@ -35,23 +38,31 @@ class pipeThread(threading.Thread):
threading.Thread.__init__(self) threading.Thread.__init__(self)
def run(self): def run(self):
global connection
while True: while True:
data = sys.stdin.buffer.read(1000) data = sys.stdin.buffer.read(1000)
try:
with connectionLock: with connectionLock:
try:
if type(connection) != bool:
connection.send(data) connection.send(data)
except Exception as e: except Exception as e:
connection = False
print(e) print(e)
pThread = pipeThread() pThread = pipeThread()
pThread.start() pThread.start()
while True: while True:
eprint("Awaiting connection...")
conn, address = serverSocket.accept() conn, address = serverSocket.accept()
eprint("Connection established, sending data.")
with connectionLock: with connectionLock:
try: try:
if type(connection) != bool:
connection.close() connection.close()
except Exception as e: except Exception as e:
print(e) print(e)
connection = conn connection = conn
connection.settimeout(15) connection.settimeout(15)