[Tutor] socket send problem

"Jörg Wölke" lumbricus at gmx.net
Wed Dec 17 06:15:04 EST 2003


> Hi,
> I have just started playing with python and sockets,
> and here is the code that I wrote:
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.connect((HOST, PORT))
>                 
> for x in self.command:
>     sent = s.send(x)

BTW: You may check, whether all data has been sent and 
- if not - call send again. This is necessary for large amounts
of data.
f.e.:

sent = 0
while sent < len(x):
       sent = sent + s.send(x)

>     print "amount sent: "+sent

print "amount sent: " + str(sent)
?

>     s.close()

After the first run you try to send data through a closed socket.

[ snip ]

> Any help/pointers would be greatly appreciated!
> Thanks,
> Helena

HTH and Greets, J"o!

-- 
"Wir können alles sehen, was sich bewegt 
und wir können alles zerstören, was wir sehen."
         -- Richard Perle

+++ GMX - die erste Adresse für Mail, Message, More +++
Neu: Preissenkung für MMS und FreeMMS! http://www.gmx.net





More information about the Tutor mailing list