Sending pictures using sockets

Dan Stromberg drsalists at gmail.com
Thu Apr 7 01:41:52 CEST 2011


On Wed, Apr 6, 2011 at 4:17 PM, Littlefield, Tyler <tyler at tysdomain.com>wrote:

> On 4/6/2011 4:58 PM, craf wrote:
>
>> >Hello.
>> >
>> >I'm testing the sockets in Python and I've seen the way in which
>> >works to send string. My question is if anyone knows where
>> >can find some information on how to send pictures through
>> >Sockets. I use Python 2.7 and have read the information regarding
>> >Sockets of the Python website, but I can not begin.
>> Pictures are just like strings; grab it, send it in binary and you are
>> set.
>
>
But you might want to frame your data somehow - say, but sending a length of
the picture before sending the picture itself, or wrapping it up in a tar
archive or something.  Sending a number indicating the number of pictures
can be helpful too.

BTW, sockets are allowed to fragment what you send, so if you send an entire
picture in a single write, it could show up as 1, 2, or 3 (or whatever)
recv's on the other end.  And if you send 3 pictures, it could arrive in 1
big recv, or 10, or whatever.  So framing your data can be very important
with sockets.

I tend to use my (OK, UCI's, but I wrote it) bufsock module to facilitate
framing, but I'm sure there are other ways.  It's described here:
http://stromberg.dnsalias.org/~strombrg/bufsock.html
And there's a newer version at
http://stromberg.dnsalias.org/svn/bufsock/trunk/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110406/c40f726a/attachment.html>


More information about the Python-list mailing list