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 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:
|
||||||
connection.send(data)
|
try:
|
||||||
except Exception as e:
|
if type(connection) != bool:
|
||||||
print(e)
|
connection.send(data)
|
||||||
|
except Exception as e:
|
||||||
|
connection = False
|
||||||
|
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:
|
||||||
connection.close()
|
if type(connection) != bool:
|
||||||
|
connection.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
connection = conn
|
connection = conn
|
||||||
connection.settimeout(15)
|
connection.settimeout(15)
|
Loading…
Reference in New Issue
Block a user