views:

17

answers:

0

I have a SocketServer.StreamRequestHandler server that calls self.rfile.readline() to read a request and then calls self.wfile.write(data) to send back some data:

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)

I want my client to be able to send the request and receive the "someOtherData" from the server:

# 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()

But the client hangs when I try this. Where am I going wrong? Also is it necessary to know how much data the socket recv's or is there a way to just receive all the data the server writes?