socket module - recv() method

mirandacascade at yahoo.com mirandacascade at yahoo.com
Mon Apr 30 16:22:23 CEST 2007


Currently using the following technique in serveral client
applications to send a request message and receive a response:

import socket
bufferSize = 500000
connectionHandle = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connectionHandle.connect(sa)
connectionHandle.sendall(requestMessage)
fullResponse = ''
# use while loop in case the entire response not sent in one chunk
while (1):
    response = connectionHandle.recv(bufferSize)
    fullResponse = fullResponse + response
    if fullResponse.find(endOfMessageText) != -1:
        break

where:
sa = 2-element tuple; 1st elem is string denoting ip address; 2nd elem
is int denoting port
requestMessage = string containing request message
endOfMessageText = string that unambiguously denotes the end of
response message

All of the client apps on which this technique is employed are very
predictable in the sense that  the client apps always know in advance
the value of endOfMessageText.

Questions:
1) is it theoretically possible that a client app will want to send a
request and receive a response where the response message does not
have something that unambigusously marks its end?
2) if so, are there any best-practices techniques for constructing the
code such that the client app knows that there is nothing else in the
response message?

Thank you.




More information about the Python-list mailing list