[Twisted-Python] Is there a nice way to write transport-agnostic protocols and servers/clients?

Jean-Paul Calderone exarkun at twistedmatrix.com
Thu Aug 17 04:13:45 MDT 2017


On Thu, Aug 17, 2017 at 1:35 AM, Kevin Conway <kevinjacobconway at gmail.com>
wrote:

> > There is no datagram endpoints API as yet, though (see #4471), only
> stream endpoints.
>
> I've read through the ticket. What I still don't understand is the
> significance of this of this? Other than some irrelevant callbacks, what
> prevents anyone from using the existing UDP endpoint? It's not clear from
> this thread why the specific transport abstraction is critically
> important to the data protocol.
>

What UDP endpoint?  There isn't one.  When I say "endpoint" I'm talking
about the Twisted API collection that centers around
*twisted.internet.endpoints*.  Is that what you're talking about?


>
> If you are building a Protocol then you use the 'dataReceived' callback
> to parse the data. Can someone elaborate on why it matters if the bytes get
> here via a datagram or TCP stream?
>

Often, protocols which have a TCP variation and a UDP variation use
different framing depending on which one they're running over.  Therefore,
you cannot have a transport-neutral  parser.  Parsing depends on the
transport.

Also, in Twisted, if you use UDP, you must implement a *DatagramProtocol* and
the *datagramReceived* method.  If you use TCP, you must implement a
*Protocol* and the *dataReceived* method.

Jean-Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20170817/23e04286/attachment-0002.html>


More information about the Twisted-Python mailing list