[Python-Dev] The socket HOWTO

"Martin v. Löwis" martin at v.loewis.de
Mon Jun 6 00:35:54 CEST 2011


> First, Twisted doesn't always use the BSD sockets API; the Windows IOCP
> reactor, especially, starts off with the socket() function, but things
> go off in a different direction pretty quickly from there.

Hmm. Are you saying it doesn't use listen, connect, bind, send, recv?
To me, that's the core of BSD sockets. I can understand it doesn't
use select(2).

> So it's
> perfectly fine to introduce yourself to networking via Twisted, and many
> users have done just that.  If you're using it idiomatically, you should
> never encounter a socket object or file descriptor poking through the
> API anywhere.

And that's all fine. I still claim that you have to *understand*
sockets in order to use it properly. By this, I mean stuff like
"what is a TCP connection? how is it established?", "how is UDP
different from TCP?", "when data arrives, what layers of software
does it go through?", "what is a port number?", etc.

> Second, it makes me a little sad that it appears to be folk wisdom that
> Twisted is only for servers.  A lot of work has gone into making it
> equally appropriate for clients.  This is especially true if your client
> has a GUI, where Twisted is often better than a protocol-specific
> library, which may either be blocking or have its own ad-hoc event loop.

I think that's because many of the problems that Twisted solves don't
exist in many of the client applications - in particular, you often
don't have many simultaneous connections. GUI apps may be the
interesting special case, but I expect that people dealing with these
rather use separate threads.

> I don't have an opinion on the socket HOWTO per se, only on the
> possibility of linking to Twisted as an alternate implementation
> mechanism.  It really would be better to say "go use Twisted rather than
> reading any of the following" than "read the following, which will help
> you understand Twisted".

Wouldn't you agree that Twisted is very difficult to learn, and thus
much heavier than sockets? And I don't blame the Twisted API for that,
but rather the mental model of overlapping activities that people have
severe problems with.

Regards,
Martin


More information about the Python-Dev mailing list