我有一个创建基本服务器的python脚本:
import socket
HOST = '*IP of server*' # Standard loopback interface address
PORT = 15000 # Port to listen on
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print('Connected by', addr)
while True:
data = conn.recv(1024)
if not data:
break
print("no data")
conn.sendall(data)
我还有一个Django项目,我想从启动Web应用程序时开始运行此脚本。我也试图让它在连接时即打印到textaera,即print('connected by',addr)
这可能吗?我环顾四周,但看起来非常利基。
谢谢