代码拉取完成,页面将自动刷新
# 此脚本在服务器运行
import socket
from multiprocessing import Process
ip = "x.x.x.x" #此处填入你服务器的内网ip
# ip = "127.0.0.1"
def handleClient(clientSocket):
recvData = clientSocket.recv(2014)
requestHeaderLines = recvData.splitlines()
for line in requestHeaderLines:
print(line)
responseHeaderLines = "HTTP/1.1 200 OK\r\n"
responseHeaderLines += "\r\n"
responseBody = "Software Started!"
response = responseHeaderLines + responseBody
clientSocket.send(response.encode())
clientSocket.shutdown(2)
clientSocket.close()
def main():
serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serverSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
serverSocket.bind((ip, 7788))
serverSocket.listen(10)
c, addr = s.accept()
print(addr, "Connected!")
flag = True
while True:
clientSocket, clientAddr = serverSocket.accept()
print(clientAddr, "Connected!")
clientP = Process(target=handleClient, args=(clientSocket,))
clientP.start()
c.send("Received!".encode())
clientSocket.close()
if __name__ == '__main__':
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((ip, 7777))
s.listen(10)
print("Listening...")
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。