標簽:
一、直接代碼
#?-*-?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:
Hello?world!
‘‘‘)connection.close()
二、?主要是??????? 發送的數據?符合HTTP格式?就可以
運行之后,瀏覽器?打開 http:127.0.0.1:8001?即可
標簽: