#!/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 bufferSize = 1000 unbufferedStdout = os.fdopen(sys.stdout.fileno(),"wb",0) # Make unbuffered stdout def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) def stringToAddressTuple(addr): rtn = addr.rsplit(":",1) rtn[1] = int(rtn[1]) rtn = tuple(rtn) return rtn def addressTupleToString(addr): return ":".join(map(str,list(addr))) serverAddr = stringToAddressTuple(sys.argv[1]) serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) eprint("Opening socket...") serverSocket.bind(serverAddr) eprint("Serving on " +addressTupleToString(serverAddr)+ "!") serverSocket.listen(1) while True: eprint("Awaiting connection...") connection, address = serverSocket.accept() eprint("Connection established, receiving data.") connection.settimeout(15) while True: data = connection.recv(bufferSize) if data == b"": break unbufferedStdout.write(data)