I write the following code to receive data, then write the data to a file.
My question is: I found the if branch (" if not data: break ") never be executed, 1). Why does the if branch never be reached? 2). How my code can exit the while loop?
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect("/var/run/output.socket")
while True:
data = s.recv(1024)
if not data:
break
else:
f = open("/home/ematt/test.log",'a')
f.write(data)