SunQuest
           Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old July 21st, 2003, 10:22 AM
SolarBear's Avatar
SolarBear SolarBear is offline
onCsdfeu
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Canada
Posts: 100 SolarBear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 7 m 43 sec
Reputation Power: 5
Send a message via ICQ to SolarBear Send a message via MSN to SolarBear
Question 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.
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.

Reply With Quote
  #2  
Old July 21st, 2003, 11:54 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 18 m 50 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #3  
Old July 21st, 2003, 12:56 PM
SolarBear's Avatar
SolarBear SolarBear is offline
onCsdfeu
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Canada
Posts: 100 SolarBear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 7 m 43 sec
Reputation Power: 5
Send a message via ICQ to SolarBear Send a message via MSN to SolarBear
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.

Reply With Quote
  #4  
Old July 21st, 2003, 02:11 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 18 m 50 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #5  
Old July 21st, 2003, 06:15 PM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 512 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 29 sec
Reputation Power: 8
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Empty list ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway