fstream/fstream-util-tcp_to_pipe.py

39 lines
967 B
Python
Raw Normal View History

#!/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
2021-04-21 11:15:53 +00:00
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)
2021-04-21 11:15:53 +00:00
eprint("Opening socket...")
serverSocket.bind(serverAddr)
serverSocket.listen(1)
while True:
2021-04-21 11:15:53 +00:00
eprint("Awaiting connection...")
connection, address = serverSocket.accept()
2021-04-21 11:15:53 +00:00
eprint("Connection established, receiving data.")
2021-04-21 10:32:52 +00:00
connection.settimeout(15)
while True:
data = connection.recv(1000)
2021-04-15 18:40:43 +00:00
if data == b"": break
sys.stdout.buffer.write(data)