Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Examples and Tutorials of SocketServer?

Reply
Thread Tools

Examples and Tutorials of SocketServer?

 
 
Milo K. Piffenpauffer
Guest
Posts: n/a
 
      12-13-2003
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
 
Reply With Quote
 
 
 
 
Paul Rubin
Guest
Posts: n/a
 
      12-13-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (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.

 
Reply With Quote
 
 
 
 
John E. Barham
Guest
Posts: n/a
 
      12-14-2003
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


 
Reply With Quote
 
Paul Rubin
Guest
Posts: n/a
 
      12-14-2003
"John E. Barham" <(E-Mail Removed)> 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.
 
Reply With Quote
 
Fredrik Lundh
Guest
Posts: n/a
 
      12-14-2003
"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>




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
COVER LETTERS RESUME EXAMPLES AND CV EXAMPLES AVAILABLE rawebadvert3 Computer Support 0 05-25-2007 04:18 AM
Examples and tutorials about popen2/3, smtplib/multipart and icq/jabber? Alessandro Bottoni Python 0 08-09-2005 05:01 PM



Advertisments