使用Python 写一个最简单的WebServer,家长意见怎么写最简单,import soc


import socket

def handle_request(client):
buf = client.recv(1024)
client.send("HTTP/1.1 200 OK\r\n\r\n")
client.send(‘<h30>Hello World</h10>‘)

def main():
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.bind((‘192.168.68.128‘,8006))
sock.listen(1)
while True:
connection,address = sock.accept()
handle_request(connection)
connection.close()
if __name__ == ‘__main__‘:
main()

以上是服务端代码,如果我们在客户端使用浏览器访问,返回helloworld到这里我们实现了一个最简单的webserver的服务端

使用Python 写一个最简单的WebServer

相关内容

    暂无相关文章

评论关闭