我有一個調用self.rfile.readline()讀取請求,然後調用self.wfile.write(數據)發回一些數據的SocketServer.StreamRequestHandler服務器:讀取數據從StreamRequestHandler發送寫
class FileServerHandler(SocketServer.StreamRequestHandler):
def handle(self):
# self.rfile is a file-like oject created by the handler
data = self.rfile.readline()
if data == "msg":
self.wfile.write(someOtherData)
我希望我的客戶能夠從服務器發送請求並收到「someOtherData」:
# Create a socket (SOCK_STREAM means a TCP socket)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, PORT))
sock.send("msg")
print sock.recv(1024)
sock.close()
但是當我嘗試這個客戶端掛起。我哪裏錯了?還有必要知道套接字recv的數據量有多少,或者是否有辦法接收服務器寫入的所有數據?