[Python-Dev] The socket HOWTO
glyph at twistedmatrix.com
Sun Jun 5 22:28:10 CEST 2011
On Jun 4, 2011, at 11:32 PM, Martin v. Löwis wrote:
> b) telling people to use Twisted or asyncore on the server side
> if they are new to sockets is bad advice. People *first* have
> to understand sockets, and *then* can use these libraries
> and frameworks. Those libraries aren't made to be black boxes
> that work even if you don't know how - you *have* to know how
> they work inside, or else you can't productively use them.
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. 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. Asyncore is different: you do need to know how sockets work in order to use it, because you're expected to call .send() and .recv() yourself. (And, in my opinion, this is a serious design flaw, for reasons which will hopefully be elucidated in the PEP that Laurens is now writing.)
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 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".
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev