zoukankan      html  css  js  c++  java
  • wgsi实现了socket-server功能

    #_author:来童星
    #date:2020/2/21
    import socket

    def handle_request(client):
    #将发送过来的信息拿到
    buf=client.recv(1024)
    #服务器的响应信息
    client.send("HTTP/1.1 200 ok ".encode('utf-8'))
    with open('index.html','rb')as f:
    data=f.read()
    client.send(data)
    #服务器将下面信息发送给浏览器,让浏览器渲染
    # client.sent("<h1 style='color:red'>hello star</h1>").encode('utf-8')

    def main():
    #main函数一旦执行,会创建一个sockek对象
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.bind(('',8001))
    sock.listen(5)


    while True:
    #如果浏览器没有发送请求,会一直卡在这里
    connection,address=sock.accept()
    print('port 8001 is running')
    #处理请求
    handle_request(connection)
    connection.close()
    if __name__=='__main__':
    main()
  • 相关阅读:
    oracle常用命令
    批量导出docker镜像
    python中的xpath
    __call__, __str__
    闭包
    ORM操作
    nginx跨域请求
    docker-compose命令
    nginx 之 websocket长连接
    nginx--proxy_set_header
  • 原文地址:https://www.cnblogs.com/startl/p/12340801.html
Copyright © 2011-2022 走看看