2021-04-15 18:38:46 +00:00
|
|
|
#!/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-24 04:59:39 +00:00
|
|
|
bufferSize = 1000
|
2021-04-21 11:15:53 +00:00
|
|
|
|
|
|
|
def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)
|
|
|
|
|
2021-04-21 12:03:25 +00:00
|
|
|
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])
|
2021-04-15 18:38:46 +00:00
|
|
|
serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
2021-04-21 11:15:53 +00:00
|
|
|
eprint("Opening socket...")
|
2021-04-15 18:38:46 +00:00
|
|
|
serverSocket.bind(serverAddr)
|
2021-04-21 12:03:25 +00:00
|
|
|
eprint("Serving on " +addressTupleToString(serverAddr)+ "!")
|
2021-04-15 18:38:46 +00:00
|
|
|
serverSocket.listen(1)
|
|
|
|
|
|
|
|
while True:
|
2021-04-21 11:15:53 +00:00
|
|
|
eprint("Awaiting connection...")
|
2021-04-15 18:38:46 +00:00
|
|
|
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)
|
2021-04-15 18:38:46 +00:00
|
|
|
while True:
|
2021-04-24 04:59:39 +00:00
|
|
|
data = connection.recv(bufferSize)
|
2021-04-15 18:40:43 +00:00
|
|
|
if data == b"": break
|
2021-04-15 18:38:46 +00:00
|
|
|
sys.stdout.buffer.write(data)
|