1 Star 2 Fork 1

音未觉/网页请求打开电脑软件

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Server.py 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
Yi nan Wang 提交于 2021-07-17 11:43 . First upload
# 此脚本在服务器运行
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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/fhwangyinan/Web_to_Software.git
git@gitee.com:fhwangyinan/Web_to_Software.git
fhwangyinan
Web_to_Software
网页请求打开电脑软件
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385