|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
||||
|
||||
|
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. Code:
import string,socket
list = []
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((socket.gethostname(), 7654))
s.listen(1)
print "Ok!"
conn, addr = s.accept()
data = conn.recv(1024) #"Hello"
data = conn.recv(1024) #"END"
conn.send("Hello Back\n")
conn.send("END\n")
i = 0
while 1:
data = conn.recv(1024)
print data
if 'END' in data:
break
else:
list.append(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
conn.send(sending)
conn.send('\n')
conn.send("END\n")
conn.close()
print list
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. 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. |
|
#2
|
||||
|
||||
|
Hi Solar,
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. Have fun, Mark. |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
||||
|
||||
|
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 ![]() Have fun, Mark. |
|
#5
|
||||
|
||||
|
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.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Empty list ? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|