拼团众筹商城系统开发(技术详细)丨拼团众筹商城开发源码版
Retail is essentially the product of technology empowerment and consumption demand upgrading.Enterprises rely on the Internet to upgrade the whole process of products from production to circulation to sales through various emerging technological means,such as big data analysis and artificial intelligence technology,and restructure the structure and industrial ecosystem of the entire retail industry.Through online service and offline experience,a new retail model is integrated. web_server.py import socket from sys import argv import gevent from gevent import monkey import time import random import re #服务器类 class WISG(object):开发分析I35案例7O98设计O7I8 def __init__(self,port,app): self.port=port self.root_dir="./HTML" #创建主套接字 self.server_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM) #允许端口重用 self.server_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) #主套接字绑定端口 self.server_socket.bind(("",self.port)) #主套接字转为被动模式,设计方案:MrsFu123 self.server_socket.listen(128) #获取web框架中的函数引用 self.app=app pass #启动服务器对象的入口函数 def run_forever(self): self.create_new_socket() pass #创建新的套接字,使用gevent,使新的套接字以消耗少量资源的协程方式运行 def create_new_socket(self): while True: new_client_socket,new_client_socket_addr=self.server_socket.accept() gevent.spawn(self.deal_accept_data,new_client_socket) #处理接收到的数据 def deal_accept_data(self,new_client_socket): recv_data=new_client_socket.recv(1024) #接收到的请求为utf-8格式,解析数据 recv_data=recv_data.decode("utf-8") #如果收到客户端发送的空字符,则关闭连接 if not recv_data: return #将接收到的数据转换为列表 recv_data_list=recv_data.splitlines() #获取请求头信息 the_request_header=recv_data_list[0] file_name=self.get_file_name(the_request_header) if file_name.endswith(".html"): print("请求的文件名为%s"%(file_name)) #向客户端发送文件 self.send_html(file_name,new_client_socket) new_client_socket.close() else:

