Newbie Question: Sockets

Grant Edwards grante at visi.com
Tue Nov 5 21:21:02 EST 2002


In article <phZx9.45806$ku2.2737094 at twister.southeast.rr.com>, Kevin Bass wrote:

>> There are no record boundaries in TCP/IP.
>>
>> One end may call send() four times with 25 bytes each time.  The other end
>> may receive that data as a single 100 byte chunk, as 5 20-byte chunks, or as
>> 100 single byte chunks.
>>
> 
> Thanks for responding. :) I will try to be a little more clear this time :)
> 
> I received the results of  'The received data is  Mousey MooMousey MooMousey
> MooMousey MooMousey MooMousey MooMousey Moo' when executing my socks. I
> hoped to get the result of ''The received data is  Mousey Moo'

You received more data than you sent?  That should never, ever happen.

> I have limited the number of bytes received in my code (data =
> conn.recv(50)) and I have recieved favorable results. I received the results
> of 'The received data is  Mousey Moo'.
> 
> Can the received data be placed into another value should as an array or
> list?

You can do anything you want with the data.  It's a Python string.  A python
string is a list of characters (bytes), which for practical purposes is
pretty much an array of 8-bit bytes.  If you want to send things other than
text strings, I suggest using

 1) The struct module to pack/unpack data using known binary layouts.
 
 2) Something like the pickle module to serialize Python objects.

-- 
Grant Edwards                   grante             Yow!  -- In 1962, you could
                                  at               buy a pair of SHARKSKIN
                               visi.com            SLACKS, with a "Continental
                                                   Belt," for $10.99!!



More information about the Python-list mailing list