你知道为什么这个循环不会中断吗?
#!/usr/bin/env python
from socket import *
import os
import sys
if __name__ == '__main__':
HOST = '127.0.0.1'
PORT = 55554
print 'Creating socket'
socketProxy = socket(AF_INET, SOCK_STREAM)
print 'bind()'
socketProxy.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
socketProxy.bind((HOST, PORT))
print 'Waiting for connection request'
socketProxy.listen(1)
conn, addr = socketProxy.accept()
print 'Connected to ', addr
request = ''
while True:
data = conn.recv(16);
if not data: break
request = request+data
print request
sys.stdout.flush()
我正在编写一个小服务器代理获取可以任意长的请求,所以我必须等到收到所有请求。无论如何,这个循环(当 len(data) == 0 时)不会停止,它会一直等待。我怎样才能阻止它?谢谢