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

Jean-Paul Calderone exarkun at twistedmatrix.com
Wed Aug 16 06:13:43 MDT 2017


On Wed, Aug 16, 2017 at 7:53 AM, Jarosław Fedewicz <
jaroslaw.fedewicz at gmail.com> wrote:

> This makes a perfect sense. (I ended up implementing it in this sorta way,
> but the other way around: it was a primarily-datagram protocol that could
> use TCP as a transport, provided there is appropriate framing.)
>
> However, while there is really a need for a shim to make use of
> polytransport protocols (DNS, syslog, SIP, NFS are a few), it looks like
> every Twisted user should bring their own. This bothers me, but just a
> little bit.
>

I don't think anyone working on Twisted has yet looked closely at these
various protocols to try to understand if there is a unifying abstraction
that would make a stream/datagram adapter possible.  There are differences
between the protocols that you mention that need to be accounted for and so
far everyone who has worked on implementations for Twisted has implemented
a custom solution for a particular protocol.  If you want to work on
figuring out what the abstraction might be, that seems useful.  I'd also
recommend you take a look at tubes <https://github.com/twisted/tubes> as a
potentially useful direction for solving this problem.


>
> Also, your reply does not address the little discrepancies that exist in
> Twisted between two kinds of datagram protocols (namely, Unix datagram
> sockets and UDP): seems like UDP APIs progressed while Unix datagram socket
> support was "left behind". I don't know if this is deliberate or not.
>

There's not as much interest in UNIX datagrams as there is in UDP.  There's
no particular reason why the UNIX datagram support shouldn't be brought up
to be on par with the UDP support.


>
> One thing that is also notably missing from the puzzle is that there is no
> support for datagram endpoints. With stream sockets, I can now use strings
> and clientFromString()/serverFromString() and be blissfully ignorant if
> it's TCP or a Unix socket. I cannot do the same with datagram sockets, I
> need to be actively aware if what I'm dealing with is a UDP socket or a
> Unix datagram socket.
>
> I'd gladly implement something to fill the gap, but I fear my contribution
> would be rejected because, say, it doesn't conform to the general direction
> Twisted is heading, whatever that may be. Or because datagram protocols are
> somehow inferior as a class. Or because Unix datagram sockets in particular
> should die and burn in hell.
>
>
Likewise, there's not as much interest in datagram transports as stream
transports.  There's no particular reason not to introduce datagram
endpoints  - someone just needs to do the work.

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


More information about the Twisted-Python mailing list