When I said indentation I was referring to the leaving of statements one line, no need to do so in python. It just increases the line noise to code ratio, which seemed high to my non-PHP trained eyes.
Quote:
|
Your code that you have posted is pretty much a match to mine but thanks anyway..
|
It is a corrected version of the code you posted. I did not run it but you appeared to be using "recvfrom" improperly and you are still overwriting the data you get from the server (data = s.recv(1024) throws out the previous received data). It will also give you an error when the socket returns None, as it does when it gets no data.
Here is a version of the code the implements the proper waiting semantics and is well commented.
def Update(s):
# Request Status
s.send("\\status\\")
# Buffer to hold incoming data
data = ''
start_time = time.time()
while True:
# Attempt to get new data
new_data = s.recv(1024)
# Handle no new data case
if not new_data:
# Drop out its been two seconds
if (time.time() - start_time) > 2:
break
else:
# Sleep 100 micro seconds
time.sleep(0.0001)
# Append new data to buffer
data += new_data
# Check for termination string
if data.find("final\\")
break
s.close()
return data.split('\\')
I don't think the odd waiting code is needed, the socket timeout is should be enough. If you set the timeout to be 2 seconds the socket will block for 2 seconds to wait for new data.