- 论坛徽章:
- 1
|
- from socket import *
- from time import ctime
- HOST='localhost'
- PORT= 9999
- BUFSIZ=1024
- ADDR=(HOST, PORT)
- sock=socket(AF_INET, SOCK_STREAM)
- sock.bind(ADDR)
- sock.listen(5)
- while True:
- print('Waiting for connection ... ')
- tcpClientSock, addr=sock.accept()
- print('Connect from ', addr)
- lines=[]
- while True:
- try:
- line=tcpClientSock.recv(BUFSIZ)
- print len(line)
- except IOError:
- print( IOError)
- tcpClientSock.close()
- break
- if not line:
- break
- lines.append(line)
- print "\n".join(lines).decode('utf8') )
- s="HTTP/1.0 200 OK\r\rContent-Length: 11\r\n\r\n<h1>ok</h1>"
- tcpClientSock.send(s.encode('utf8'))
- tcpClientSock.close()
- sock.close()
复制代码
用浏览器模拟请求,一直没回应,就是不会break
|
|