[Tutor] sockets
Sean 'Shaleh' Perry
shalehperry@comcast.net
Wed Jul 9 20:42:02 2003
On Wednesday 09 July 2003 17:20, Rob Hudson wrote:
>
> data = sockobj.recv(1024)
>
>
> I call it like this:
> python socket-test.py 132.163.4.203 13
>
>
> My question is: What if the data the server sends is more than 1024
> bytes? Python can't do this, right?
>
> while (recv = sockobj.recv(1024)):
> data += recv
>
> Specifically, I think Python can't make an assignment inside a
> conditional. Would you get the data, then check for NULL and break if
> the data is empty? Or check for EOF? Something like that?
>
you are correct, no assignment in conditionals.
One of the tricks to socket programming is the value passed to recv() is a
MAXIMUM. The OS may decide to only give you 1/3, 1/8, 5/8, etc. of that
value. So you have to check that you have received all of the data.
This leads to the recv being called in a loop and the value being checked
until the proper amount has been received or the data contains what you
expect it to.