Examples and Tutorials of SocketServer?

Discussion in 'Python' started by Milo K. Piffenpauffer, Dec 13, 2003.

  1. I've looked on Google for examples of using the SocketServer module,
    but I'm not having much luck. The online documentation is pretty
    sparse, and PyDoc isn't very clear. Does anyone know where I could
    find an example of SocketServer that explains what the various
    features of the code do?

    Milo
     
    Milo K. Piffenpauffer, Dec 13, 2003
    #1
    1. Advertising

  2. Milo K. Piffenpauffer

    Paul Rubin Guest

    (Milo K. Piffenpauffer) writes:
    > I've looked on Google for examples of using the SocketServer module,
    > but I'm not having much luck. The online documentation is pretty
    > sparse, and PyDoc isn't very clear. Does anyone know where I could
    > find an example of SocketServer that explains what the various
    > features of the code do?


    "Use the source, Luke". I remember having the same problem and
    finding some better docs around somewhere though.
     
    Paul Rubin, Dec 13, 2003
    #2
    1. Advertising

  3. Paul Rubin wrote:
    > Milo K. Piffenpauffer writes:
    > > I've looked on Google for examples of using the SocketServer module,
    > > but I'm not having much luck. The online documentation is pretty
    > > sparse, and PyDoc isn't very clear. Does anyone know where I could
    > > find an example of SocketServer that explains what the various
    > > features of the code do?

    >
    > "Use the source, Luke".


    Ditto. Admittedly it can be confusing figuring out which of the methods you
    need to override.

    Here's a slightly edited minimal echo server from the printed Python
    Cookbook (i.e., I couldn't find it in the Cookbook on the ActiveState
    website):

    import SocketServer

    class EchoHandler(SocketServer.BaseRequestHandler):
    def handle(self):
    while 1:
    data = self.request.recv(1024)
    if not data: break
    self.request.send(data)

    EchoServer = SocketServer.TCPServer(("", 8881), EchoHandler)
    EchoServer.serve_forever()

    Run the above and see it in action by doing "telnet localhost 8881" and
    typing away. The characters you type should be repeated (i.e., echoed). At
    least that's what happens for me on XP...

    Note that you don't even have to derive your server from one in
    SocketServer. All you have to do minimally is sub-class the
    BaseRequestHandler class and override the handle() method.

    Note too that the standard library's SimpleHTTPServer is based on
    SocketServer.TCPServer (via HTTPServer in BaseHTTPServer) so it's a good,
    albeit more complex, example of a SocketServer server.

    But at some point you should read and try to trace the source to
    SocketServer. Really, it's not that complicated.

    John
     
    John E. Barham, Dec 14, 2003
    #3
  4. Milo K. Piffenpauffer

    Paul Rubin Guest

    "John E. Barham" <> writes:
    > But at some point you should read and try to trace the source to
    > SocketServer. Really, it's not that complicated.


    It's actually pretty educational to see how such things are written.
    The way the threading and forking mixins work is quite elegant.
     
    Paul Rubin, Dec 14, 2003
    #4
  5. "Milo K. Piffenpauffer" wrote:

    > I've looked on Google for examples of using the SocketServer module,
    > but I'm not having much luck. The online documentation is pretty
    > sparse, and PyDoc isn't very clear. Does anyone know where I could
    > find an example of SocketServer that explains what the various
    > features of the code do?


    http://www.effbot.org/zone/librarybook-index.htm

    chapter 7 might be of some help.

    </F>
     
    Fredrik Lundh, Dec 14, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kenneth Porter

    Tutorials/examples for SAX2 with Perl

    Kenneth Porter, Dec 13, 2003, in forum: XML
    Replies:
    2
    Views:
    503
    Tad McClellan
    Dec 13, 2003
  2. Frederick Grim

    SocketServer class examples

    Frederick Grim, Jul 18, 2004, in forum: Python
    Replies:
    0
    Views:
    353
    Frederick Grim
    Jul 18, 2004
  3. Adil Hasan

    SocketServer class examples

    Adil Hasan, Dec 11, 2004, in forum: Python
    Replies:
    0
    Views:
    600
    Adil Hasan
    Dec 11, 2004
  4. Alessandro Bottoni
    Replies:
    0
    Views:
    503
    Alessandro Bottoni
    Aug 9, 2005
  5. Replies:
    5
    Views:
    1,485
Loading...

Share This Page