THost / app.py
Staticaliza's picture
Update app.py
bc84963 verified
raw
history blame contribute delete
517 Bytes
# app.py
import os,socket,threading,sys
port=int(os.getenv("PORT","5678"))
print("echo tcp on",port,flush=True)
def handle(c,a):
print("conn",a,flush=True)
while (d:=c.recv(1024)):
print("recv",d.decode(errors="ignore").strip(),flush=True)
c.sendall(d)
c.close()
print("disc",a,flush=True)
s=socket.socket()
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
s.bind(("0.0.0.0",port))
s.listen()
while True:
threading.Thread(target=handle,args=s.accept(),daemon=True).start()