ThreadingUDPSocketServer drop/reject?

James R. Saker Jr. jsaker at
Fri Sep 24 16:18:56 CEST 2004

Didn't see a reply to my request but I figured it out using
DatagramRequestHandler under SocketServer:

"USAGE: %s <port>"
from SocketServer import DatagramRequestHandler, UDPServer
from sys import argv

class EchoHandler(DatagramRequestHandler):

   def handle(self):

      ## Assume following three addresses are legit; var placed
      ## here for simplicity in test; would be referred from elsewhere
      ## in real instance instead of local 'addrList'

      addrList = ['', '', '']

      if self.client_address[0] in addrList:
        print "Client connected:", self.client_address
        message =
        print "Message was: %s" % message
         print "Rejected %s" % self.client_address[0]

if len(argv) != 2:
   print __doc__ % argv[0]
   UDPServer(('',int(argv[1])), EchoHandler).serve_forever()

Result: Hosts in addrList can access echo server; hosts not in addrList
are rejected (not sure if this a UDP drop or reject; need to look into
further I'd expect on detailed UDP drop/reject behavior.


More information about the Python-list mailing list