problem with sockets and transferring binary files

thebiggestbangtheory at gmail.com thebiggestbangtheory at gmail.com
Wed Jun 3 01:52:40 EDT 2009


On Jun 2, 10:29 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Wed, 03 Jun 2009 01:54:02 -0300, <thebiggestbangthe... at gmail.com>  
> escribió:
>
> >            I am a python newbie. I am now progressing to writing a
> > network app in python to learn more about it. [...]
> > Surprisingly, the sha1 hash of the encrypted data before it is sent
> > from server is different  from the encrypted file data received by the
> > client.
> >           data = connection.recv(10000000) # receive up to 10000000
> > bytes
>
> recv returns *up* *to* 10000000 bytes: maybe only one byte.
> You'll have to keep recv'ing the pieces until you get an empty string  
> (when client closes the connection), or send the file size first and then  
> the actual data.
>
> >             buf = open(currentpath+'received-container.tar.gz', 'w')
> >             buf.write(info)
> >             buf.close()
>
> If you're on Linux it doesn't matter, but the 'w' above should be 'wb' for  
> a binary file.
>
> > def send_to_sender(cipher, servername):
> >     ...
> >     clientSocket.send(cipher)
>
> Similar to recv above: send() might not send the whole string at once (try  
> sendall instead).
>
> --
> Gabriel Genellina

Thanks! :-) very helpful



More information about the Python-list mailing list