标签:
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的服务端
标签:
原文地址:http://www.cnblogs.com/yjz1/p/5487203.html