zoukankan      html  css  js  c++  java
  • 网站服务

    # coding:utf-8
    import socket
    from multiprocessing import Process
    HTML_ROOT_DIR = ""

    def handle_client(client_socket):
    """处理客户端请求"""
    # 获取客户端请求数据
    request_data = client_socket.recv(1024)
    print("request data:", request_data)

    # 构造响应数据
    response_start_line = "HTTP/1.1 200 OK "
    response_headers = "Server: My server "
    response_body = "hello itcast 你是我的夜晚"
    response = response_start_line + response_headers + " " + response_body
    print("response data:", response)

    # 向客户端返回响应数据
    client_socket.send(bytes(response, "utf-8"))

    # 关闭客户端连接
    client_socket.close()


    if __name__=="__main__":
    server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server_socket.bind(("", 8000))
    server_socket.listen(120)

    while True:
    client_socket, client_address = server_socket.accept()
    # print("[%s, %s]用户连接上了"%client_addrest[0],client_address[1])
    print("[%s, %s]用户连接上了" % client_address)
    handle_client_process = Process(target=handle_client, args=(client_socket,))
    handle_client_process.start()
    client_socket.close()


    随后在页面的地方输入
    127.0.0.1:8000 

  • 相关阅读:
    日期类和包装类
    集合——list
    数组
    多态小结
    一些概念性的知识点
    简单的图书管理系统
    一个小总结
    python-web自动化:上传操作
    python-web自动化:日期框操作
    python-web自动化:滚动条
  • 原文地址:https://www.cnblogs.com/yuanjia8888/p/10187852.html
Copyright © 2011-2022 走看看