Status messages for util-pipe_to_tcp
This commit is contained in:
parent
a377f8f584
commit
0c025cbf7f
@ -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)
|
Loading…
Reference in New Issue
Block a user