[Python-Dev] The socket HOWTO
glyph at twistedmatrix.com
Tue Jun 7 05:54:12 CEST 2011
On Jun 5, 2011, at 3:35 PM, Martin v. Löwis wrote:
> 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.
Yes, these are all excellent concepts to be familiar with. But the word "socket" (and the socket HOWTO) refers to a specific way to interface with those concepts, the Berkeley socket API: <http://en.wikipedia.org/wiki/Berkeley_sockets>. Which you don't have to know anything about if you're going to use Twisted. You should know about IPC in general, and TCP/UDP specifically if you're going to use Twisted, but sockets are completely optional.
Also, I feel that I should point out that the sockets HOWTO does not cover even a single one of these concepts in any useful depth. If you think that these are what it should be explaining, it needs some heavy editing. Here's what it has to say about each one:
> what is a TCP connection?
The only place that the characters "TCP" appear in the entire document is in the phrase "... which is completely different from TCP_NODELAY ...". Nowhere is a TCP connection explained at a conceptual level, except to say that it's something a web browser does.
> how is UDP different from TCP?
The phrase "UDP" never appears in the HOWTO. DGRAM sockets get a brief mention as "anything else" in the sentence: "... you’ll get better behavior and performance from a STREAM socket than anything else ...". (To be fair, I do endorse teaching that "the difference between TCP and UDP is that you should not use UDP" to anyone not sufficiently advanced to read the relevant reference documentation themselves.)
> when data arrives, what layers of software does it go through?
There's no discussion of this that I can find at all.
> what is a port number?
Aside from a few comments in the code examples, the only discussion of port numbers is "low number ports are usually reserved for “well known” services (HTTP, SNMP etc)."
It would be very good to have a "Python networking overview" somewhere that explained this stuff at a very high level, and described how data might get into or out of your program, with links to things like the socket HOWTO that describe more specific techniques. This would be useful because most commonly, I think that data will get into Python network programs via WSGI, not direct sockets or anything like Twisted.
To be clear, having read it now: I do _not_ agree with Antoine that this document should be deleted. I dimly recall that it helped me understand some things in the very early days of Twisted. While it's far from perfect, it might help someone in a similar situation understand those things as well today. I just found it interesting that the main concepts one would associate with such a HOWTO are nowhere to be found :).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev