Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #96915
| Path | csiph.com!news.swapon.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail |
|---|---|
| Return-Path | <cameron@cskk.homeip.net> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'binary': 0.05; 'url:bitbucket': 0.05; '21,': 0.07; 'bits': 0.07; 'bytes.': 0.07; 'implements': 0.07; 'method,': 0.07; 'prefix': 0.07; 'cc:addr :python-list': 0.09; 'buffer.': 0.09; 'compact': 0.09; 'empty,': 0.09; 'encode': 0.09; 'endian': 0.09; 'flush': 0.09; 'follows.': 0.09; 'integers': 0.09; 'length.': 0.09; 'nb:': 0.09; 'protocols.': 0.09; 'semantics': 0.09; 'unsigned': 0.09; 'thread': 0.10; 'value.': 0.15; '155': 0.16; '>on': 0.16; 'fp.close()': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'interest,': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'octets': 0.16; 'packets.': 0.16; 'pipes': 0.16; 'sequencing': 0.16; 'simpson': 0.16; 'tcp': 0.16; 'udp,': 0.16; 'url:py': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'byte': 0.18; 'skip:l 30': 0.18; 'tests': 0.18; '>>>': 0.20; 'library': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'preferred': 0.20; 'do.': 0.22; '%s"': 0.22; 'embedding': 0.22; 'sep': 0.22; 'visible': 0.22; 'cheers,': 0.22; 'am,': 0.23; 'bit': 0.23; 'this:': 0.23; 'implemented': 0.24; 'unix': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'header:User-Agent:1': 0.26; 'chris': 0.26; 'error': 0.27; 'actual': 0.28; 'protocols': 0.29; 'queue': 0.29; 'raise': 0.29; 'that.': 0.30; 'code': 0.30; 'probably': 0.31; "can't": 0.32; 'class': 0.33; 'url:python': 0.33; 'stream': 0.33; '(for': 0.34; 'weeks': 0.34; 'add': 0.34; 'list': 0.34; 'gets': 0.35; 'formats': 0.35; 'mine': 0.35; 'protocol': 0.35; 'unit': 0.35; 'but': 0.36; 'url:org': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'charset:us- ascii': 0.37; 'several': 0.38; 'skip:p 20': 0.38; 'means': 0.39; 'data': 0.39; 'format': 0.39; 'whatever': 0.39; 'easily': 0.39; 'some': 0.40; 'chance': 0.60; 'avoid': 0.61; 'here:': 0.63; 'cameron': 0.66; 'below.': 0.66; 'home': 0.67; 'subject': 0.70; 'received:61': 0.72; '128,': 0.84; 'exercised': 0.84; 'streams': 0.84 |
| X-Authentication-Info | Submitted using ID cskk@bigpond.com |
| X-Authority-Analysis | v=2.0 cv=D6DF24tj c=1 sm=1 a=aFr8NDWZP0ValyFosMJopQ==:17 a=vrnE16BAAAAA:8 a=ZtCCktOnAAAA:8 a=ff-B7xzCdYMA:10 a=pGLkceISAAAA:8 a=xtERp6CFAAAA:8 a=m41ag75paz-yV791GvsA:9 a=CjuIK1q_8ugA:10 a=dLm9PCUIzdXIxVvp:21 a=fpJHLvXXJFndxq3l:21 a=aFr8NDWZP0ValyFosMJopQ==:117 |
| Date | Mon, 21 Sep 2015 16:27:13 +1000 |
| From | Cameron Simpson <cs@zip.com.au> |
| To | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Subject | Re: Lightwight socket IO wrapper |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii; format=flowed |
| Content-Disposition | inline |
| In-Reply-To | <CAPTjJmpuYp5uEDnRJqC9qKj-YkNRx1jW48WsRyRn+U0rzGiTYw@mail.gmail.com> |
| User-Agent | Mutt/1.5.23 (2014-03-12) |
| References | <CAPTjJmpuYp5uEDnRJqC9qKj-YkNRx1jW48WsRyRn+U0rzGiTYw@mail.gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.21.1442816849.28679.python-list@python.org> (permalink) |
| Lines | 73 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1442816849 news.xs4all.nl 23864 [2001:888:2000:d::a6]:57585 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:96915 |
Show key headers only | View raw
On 21Sep2015 12:40, Chris Angelico <rosuav@gmail.com> wrote:
>On Mon, Sep 21, 2015 at 11:55 AM, Cameron Simpson <cs@zip.com.au> wrote:
>> On 21Sep2015 10:34, Chris Angelico <rosuav@gmail.com> wrote:
>>> If you're going to add sequencing and acknowledgements to UDP,
>>> wouldn't it be easier to use TCP and simply prefix every message with
>>> a two-byte length?
>>
>> Frankly, often yes. That's what I do. (different length encoding, but
>> otherwise...)
>
>Out of interest, what encoding?
NB: this is for binary protocols.
I don't like embedding arbitrary size limits in protocols or data formats if I
can easily avoid it. So (for my home grown binary protocols) I encode unsigned
integers as big endian octets with the top bit meaning "another octet follows"
and the bottom 7 bits going to the value. So my packets look like:
encoded(length)data
For sizes below 128, one byte of length. For sizes 128-16383, two bytes. And so
on. Compact yet unbounded.
My new protocols ar probably going to derive from the scheme implemented in
the code cited below. "New" means as of some weeks ago, when I completely
rewrote a painful ad hoc protocol of mine and pulled out the general features
into what follows.
The actual packet format is implemented by the Packet class at the bottom of
this:
https://bitbucket.org/cameron_simpson/css/src/tip/lib/python/cs/serialise.py
Simple and flexible.
As for using that data format multiplexed with multiple channels, see the
PacketConnection class here:
https://bitbucket.org/cameron_simpson/css/src/tip/lib/python/cs/stream.py
Broadly, the packets are length[tag,flags[,channel#],payload] and one
implements whatever semantics one needs on top of that.
You can see this exercised over UNIX pipes and TCP streams in the unit tests
here:
https://bitbucket.org/cameron_simpson/css/src/tip/lib/python/cs/stream_tests.py
On the subject of packet stuffing, my preferred loop for that is visible in the
PacketConnection._send worker thread method, which goes:
fp = self._send_fp
Q = self._sendQ
for P in Q:
sig = (P.channel, P.tag, P.is_request)
if sig in self.__sent:
raise RuntimeError("second send of %s" % (P,))
self.__sent.add(sig)
write_Packet(fp, P)
if Q.empty():
fp.flush()
fp.close()
In short: get packets from the queue and write them to the stream buffer. If
the queue gets empty, _only then_ flush the buffer. This assures synchronicity
in comms while giving the IO library a chance to fill a buffer with several
packets.
Cheers,
Cameron Simpson <cs@zip.com.au>
ERROR 155 - You can't do that. - Data General S200 Fortran error code list
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Lightwight socket IO wrapper Cameron Simpson <cs@zip.com.au> - 2015-09-21 16:27 +1000
csiph-web