Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53093
| References | <f543172d-85e6-467d-9fc8-f59d41381edd@googlegroups.com> <mailman.245.1377547782.19984.python-list@python.org> <2f3e7c96-45a7-485c-bfc7-18bf9841114b@googlegroups.com> <521d0a99$0$15900$e4fe514c@news.xs4all.nl> |
|---|---|
| Date | 2013-08-28 06:40 +1000 |
| Subject | Re: How to check client shutdown? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.284.1377636010.19984.python-list@python.org> (permalink) |
On Wed, Aug 28, 2013 at 6:22 AM, Irmen de Jong <irmen.NOSPAM@xs4all.nl> wrote: > ? What is the actual downside of having >> the server set to anticipate a message length which is known to be more than will be >> sent (or be allowed to be sent?), for example connection.recv(10000). Does not the >> receiver know the size after the fact? Is it impacting performance somehow (I haven't >> noticed anything in my tests) > > The issue is that recv() is not guaranteed to return you the full amount of data that is > requested. It may very well just return a single byte, and leave the rest for later. The > argument is an upper bound on the amount of data you receive. So to make your recv > reliable, you need to have a means of deciding when the 'full' amount of data has been > collected. As Chris already suggested, this is usually done by putting the recv() in a > loop and collecting data until it reaches a length that you precisely know beforehand, > or by detecting a special end-of-message marker in the data stream, such as a newline. Right. When you use TCP sockets, there's no boundaries, so you could get two pickles in one recv, or you could get one and a half, or anything. It depends partly on your buffer sizes and things; if you're sending very short messages (less than a kilobyte), and have long delays between them, chances are you'll get one write in one read; but it's not guaranteed. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to check client shutdown? Paul Pittlerson <menkomigen6@gmail.com> - 2013-08-26 12:45 -0700
Re: How to check client shutdown? Chris Angelico <rosuav@gmail.com> - 2013-08-27 06:09 +1000
Re: How to check client shutdown? Paul Pittlerson <menkomigen6@gmail.com> - 2013-08-27 10:44 -0700
Re: How to check client shutdown? Andrew Berg <robotsondrugs@gmail.com> - 2013-08-27 15:17 -0500
Re: How to check client shutdown? Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2013-08-27 22:22 +0200
Re: How to check client shutdown? Chris Angelico <rosuav@gmail.com> - 2013-08-28 06:40 +1000
Re: How to check client shutdown? Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2013-08-27 22:49 +0200
Re: How to check client shutdown? MRAB <python@mrabarnett.plus.com> - 2013-08-26 21:20 +0100
Re: How to check client shutdown? Grant Edwards <invalid@invalid.invalid> - 2013-08-26 20:24 +0000
csiph-web