SocketServer class examples

Daniel Eloff danieleloff at
Mon Jul 19 00:32:29 CEST 2004

Just a suggestion, but if you're doing any networking code, I would use
Twisted ( ). It's fast and remarkably easy
to use. I don't think there is anything quite as good in any language
that I've used. If you don't have a big investment in code you might
consider it, or keep it in mind for future work.

Implementing an echo server with Twisted is a mere half dozen lines of

I created an entire proxy server (that works for any line based
protocol) in a mere 30 lines of code (counting whitespace). And I'm a
Python newbie :)

-----Original Message-----
From: at
[ at] On
Behalf Of Frederick Grim
Sent: Sunday, July 18, 2004 11:34 AM
To: python-list at
Subject: SocketServer class examples 

Howdy group,
    So I am in the middle of using the socketserver class from the std
library and have run into a problem that probably reveals my
misunderstanding of sockets.  I have a class defined like so:

class tcp_listener(SocketServer.ThreadingTCPServer):
        def __init__(self, addr, port):
                SocketServer.ThreadingTCPServer.__init__(self, \
                    (addr, port), Daemon.request_handler)

""" Yes I realize the above is silly and redundant """

And a request handler in Daemon that has a handle function that works
    def __req_handle(self, req):
        """ Do stuff with req and return a response afterwards """
        return response

    def handle(self);
        while True:
            input = self.rfile.readline()
            request = input
            while input and not'EOF$', input):
                input = self.rfile.readline()
                request += input


The client end looks almost identical to the example in the python docs.
the problem here is that this code doesn't work.  Using tcpdump I can
that the client is sending to the server properly but the server is
responding.  Or when it tries to respond it gets stuck in the write.
going on here.  I can't seem to find a single example of how to use this
class on the client and server side and I don't want to use twisted
I should understand how this works instead of relying on canned
Does anyone know where I can find an example of a functioning
and client? Google seems to help nought here.


More information about the Python-list mailing list