[Tutor] simple server and client question

Remco Gerlich scarblac@pino.selwerd.nl
Tue, 13 Feb 2001 23:52:22 +0100

On Tue, Feb 13, 2001 at 02:30:52PM -0600, Rob Andrews wrote:
> I hate to even ask this one, because it just doesn't *feel* specific
> enough, but my sad little plea will have to do.
> The mandate has come from above that I write a simple server and client
> in Python in preparation for a project in development.  The server and
> client can do absolutely anything, and barely that, if I so choose, as
> they will not be used in the project (unless my code is brilliant enough
> to be useful for the project, I suppose, which is unlikely as it's a
> Java project).  The important thing is that I understand how to write
> such things.
> So if anyone can recommend any good sources I can absorb and start
> tinkering, I'd be mighty appreciative.

If you get the source distribution of Python, there is quite some stuff in
the Demo/ and Tools/ dirs, and the standard library of course. 

In Demo/sockets, there is a "hello world" style unix socket client and a
socket server (unixclient.py and unixserver.py). Understand these first.
Then there are sample implementations of all kinds of clients in that dir.
Try to make a little server that listen for connections, and a client that
can connect to it, so you can send text messages to the screen of the server.
This is the lowest level.

Now play with http. With the standard module BaseHTTPServer you can make a
simple web server and run it. With urllib you can send requests to web
servers. Try if you can get them to work together. This is high level.

Now I don't know how the HTTP server actually works, maybe you need threads
as well.

Now the first thing I would think of to make as a test case is a chat server
where multiple people can login and they all see each other's messages :).

XML-RPC might be fun to look into as well - send complex datatype to another
python program by turning it into xml and giving it to a web server. There's
a good library for this at www.secretlabs.com, if I recall correctly.

So, this is how I would approach it.

Remco Gerlich