Hi everyone.
This post is incorrectly tagged 'send' since I cannot create new tags.
I have a very basic question about this simple echo server. Here are some code snippets.
client
while True:
data = raw_input("Enter data: ")
mySock.sendall(data)
echoedData = mySock.recv(1024)
if not echoedData: break
print echoedData
server
while True:
print "Waiting for connection"
(clientSock, address) = serverSock.accept()
print "Entering read loop"
while True:
print "Waiting for data"
data = clientSock.recv(1024)
if not data: break
clientSock.send(data)
clientSock.close()
Now this works alright, except when the client sends an empty string (by hitting the return key in response to "enter data: "), in which case I see some deadlock-ish behavior.
Now, what exactly happens when the user presses return on the client side? I can only imagine that the sendall call blocks waiting for some data to be added to the send buffer, causing the recv call to block in turn. What's going on here?
Thanks for reading!