标签:
一、直接代码
# -*- coding: utf-8 -*- import socket __author__ = ‘lpe234‘ __date__ = ‘2015-03-12‘ if __name__ == ‘__main__‘: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind((‘127.0.0.1‘, 8001)) sock.listen(5) while True: connection, address = sock.accept() content = connection.recv(1024) print content connection.settimeout(5) connection.send(‘‘‘HTTP/1.1 200 OK Context-Type: text/html; charset=utf-8 Server: Python-slp version 1.0 Context-Length: <h1>Hello world!</h1>‘‘‘) connection.close()
二、 主要是 发送的数据 符合HTTP格式 就可以
运行之后,浏览器 打开 http:127.0.0.1:8001 即可
标签:
原文地址:http://my.oschina.net/lpe234/blog/386282