Q: How to UDPServer ??

Å£·à drjohn at 21cn.edu.cn
Wed Jan 1 21:59:04 CET 2003


I have some problems in the quote_srv.py I write as below, quote server on
TCP works well, but I can get no message on the UDP mode, are there some
problems in the QutoeMyxinHandler ??
---------------------------------
#!/usr/bin/env python

# File: quote_srv.py
# Author:   John Fractal <JohnFractal at 163.com>
# Description:
#   This program is just one of my exercises while learning socket
# programming under Python.
#

from SocketServer import *

response = 'Quote Server by John Fractal <JohnFractal at 163.com>'
quote_port = 17

class QuoteMixinHandler:
    def handle(self):
        self.wfile.write(response)
        self.wfile.close()

class TCPQuoteHandler(QuoteMixinHandler, StreamRequestHandler):
    pass

class UDPQuoteHandler(QuoteMixinHandler, DatagramRequestHandler):
    pass

if __name__=='__main__':
    UDPQuoteSrv = UDPServer( ('', quote_port), UDPQuoteHandler )
    TCPQuoteSrv = TCPServer( ('', quote_port), TCPQuoteHandler )

    UDPQuoteSrv.server_activate()
    TCPQuoteSrv.serve_forever()







More information about the Python-list mailing list