[Tutor] creating a server
Alan Gauld
alan.gauld at yahoo.co.uk
Wed Oct 7 17:20:07 EDT 2020
On 07/10/2020 20:13, nathan tech wrote:
> that's what part of my question was, really :) how does one go about
> verifying all data was received?
>
> recv(2000000)
>
> seems a bit ludicrous to me
It is, instead you use a loop to read the whole message:
msg = ''
while true:
data = recv(blocksize) # or whatever
msg += data
if len(data) < blocksize: break # end of data
> and besides, what you don't want to do is
> receive an object and then half of the next one, too!
Hopefully the sender sends them one at a time! Or at least
your message protocol stipulates that they are sent one
at a time(or in a stipulated amount, or that the number
of objects is specified in the message. Whatever it
takes for you to decode the received bytes.
Servers stipulate their API. If clients don't abide by
the API that's their problem not the servers!
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list