July 21st, 2003, 10:22 AM
Empty list ?
Hi everybody, I'm new here and I'm totally clueless.
I'm new to Python, and I have to admit I've never spent so much time debugging a program. I have absolutely no idea about what's NOT going on.
So a script connects to this one and sends a series of 100 integers, and when it's done I received a "END" signal. The program then sends "minimum:maximum" and then "END". If all is correct, I should get some message.
list = 
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn, addr = s.accept()
data = conn.recv(1024) #"Hello"
data = conn.recv(1024) #"END"
i = 0
data = conn.recv(1024)
if 'END' in data:
i = i + 1
for i in range(100):
list[i] = int(string.strip(list[i]))
maximum = max(list)
minimum = min(list)
sending = str(minimum) + ":" + str(maximum) + '\n'
print "Sending ", sending
The problem is that I DO receive data : my print data does output the data I receive, but I get a list with only the first integer at the end. Why is the list empty ?
EDIT : put the full code + changed some details
Last edited by SolarBear; July 21st, 2003 at 01:13 PM.
July 21st, 2003, 11:54 AM
can you post the other script because i can't really test it without that . On the pluss side i cant see a problem with this code. maybe your other isn't sending correctly?
There's a great section about python and sockes in "Python Web Programming" infact i think they use a similar example as your script above.
July 21st, 2003, 12:56 PM
Well I'm sorry to say maybe I can't. It's part of a challenge on http://www.slyfx.com. Maybe you can access it, but I'm not sure.
The URL is http://www.slyfx.com/cgi-bin/sock.pl?ip=0.0.0.0 , where the IP is your own IP. It first sends "Hello" and then "END", then you reply "Hello Back" and then "END". Only after that do you receive the integers and then another "END".
The home-made handshake is OK since I don't any error, it's just after that I get problems.
Anyways, thanks for the heads up I'll look for that section about web programming.
EDIT : For clarity, I have put the complete code up there, just in case. I had it stripped down to the bare minimum, but there may be some other bug somewhere else.
Last edited by SolarBear; July 21st, 2003 at 01:10 PM.
July 21st, 2003, 02:11 PM
Ah so let me get this right, the socket is sent from a website (which you have no access to). If your looking for end in the socket data then surly the loop will exit before you even get the int's because the inisial "Hello, END". I dont know thats only a guess. Do you know for sure that this website's script works?
Anyway i'll think about the problem and get back to you
July 21st, 2003, 06:15 PM
For reference, you can always develop scripts like this on your own machine first, making both clients then getting them to message each other, so you can be sure what data is being sent and received.