steve at holdenweb.com
Mon Aug 22 14:29:12 CEST 2005
Tom Anderson wrote:
> On Sun, 21 Aug 2005, John Walton wrote:
>>Hello, everyone. I just began school, and they already assigned us
>>science fair. Since I'm in 8th grade, I get to do demonstrations for
>>our projects. I'm probably going to demonstrate Python's networking
>>capabilities by writing a simple instant messenger program. I only have
>>a few problems:
>>1. I know squat about Python network Programming
>>2. I know nothing about networks
>>So if any of you know of a good Python Networking Tutorial or a website
>>with lots of information on networks and networking, please reply.
> There are two sides to this problem. The first is understanding networks
> in general, and the specific application protocols you're interested in.
> When i say 'understanding networks in general', don't panic - i don't mean
> you need to understand everything about how the internet works. In fact,
> you don't really need to understand *anything* about how the internet
> works, you just need to understand the interfaces it exposes to you. And,
> helpfully, that interface is pretty simple: a program can get a connection
> to another program, running on a different machine, which amounts ot a
> pipe for bytes - both ends can write bytes to the pipe when they feel like
> it, and those bytes become available for the other end to read. To open
> one of these connections, you need to know the hostname or IP address of
> the computer at the far end, and something called a 'port number', which
> is basically a way of identifying which program on that machine you want
> to talk to; if you want other programs to be able to open connections to
> your program, you have to pick a port number and ask the system to give
> you any connections that are made to it.
> That's pretty much it for the network fundamentals. There is more -
> datagram sockets, looking up IP addresses, doing funky things with sockets
> - but you can forget about that until you've mastered the basics.
I tried to cover those basics as briefly as possible in the tutorial I
mentioned earlier. I'd appreciate your comments on how well I succeeded.
> What you do need to understand beyond this, though, is about the
> application protocol you're using. The network just gives you a way to
> move streams of bytes; in order to actually do anything useful, you need
> an agreement between the programs at either end of the connection about
> what those bytes mean - that's an application protocol. It's basically a
> file format as applied to a network connection instead of a file. Each
> application protocol is completely different to every other one (well,
> there are a lot of similarities, but they're mostly different), so you'll
> need to read up on the one you want to use (or invent your own!) - the
> documentation is (almost always) in the form of a document unhelpfully
> called a Request For Comments, or RFC; the internet RFCs are published
> For example, here's the RFC for HTTP version 1.0:
> RFCs can be pretty heavy going, but they are *the* definitive
> specifications, so they're worth reading. Once you're used to them,
> they're often easier to read than tutorials, i find.
Not for newbies, though very useful for ensuring high levels of
interoperability (and fascinating when you start to realize that real
products bend the RFCs in various ways).
> The second thing is understanding how to do network programming in python.
> There's a well-established API in C for network programming - the socket
> API - which comes from UNIX; python uses a fairly simple translation of
> this as its network API (look in the 'socket' package). The good thing
> about this is that this API is well-understood and well-documented. The
> bad thing is that it's a bit of a mess (compare and contrast to the API in
> Java if you don't believe me). There's detailed documentation for the
> socket module here:
But then Java's a bit of a mess as a language when compared with Python,
I should say. While I know the language has many adherents, it also
seems to have many programmers who only know enough to follow recipes.
This latter feature is a symptom of the language's popularity, so I
suppose we should expect the same problems in about twenty years when
Python becomes more popular than Java.
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list