[Tutor] Practicing with sockets
Danny Yoo
dyoo at hashcollision.org
Fri Oct 31 22:42:48 CET 2014
>
>
> I also reread the docs at https://docs.python.org/2/howto/sockets.html and
> decided to remove the "b" from "open('myfile.png', 'wb') open('myfile.png',
> 'rb') seeing how binary could be different depending on the machine and I
> have not yet learned how to deal with this.
>
Whoa, wait. I think you're misunderstanding the point of binary mode. You
_definitely_ need binary mode on when working with binary file formats like
PNG. Otherwise, your operating system environment may do funny things to
the file content like treat the 0-character (NULL) as a terminator, or try
to transparently translate line ending sequences.
Would I be better off converting the image to base64 prior to sending it to
> the server, then decoding it on the server?
>
The socket approach is low-level: all you've got is a pipe that can send
and receive bytes. It's _all_ binary from the perspective of the network
layer. base64-encoding and decoding these bytes won't harm anything, of
course, but I don't see it helping either.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141031/56ad90b0/attachment.html>
More information about the Tutor
mailing list