def run(self):
     while True:
         try:
             conn, addr = self.listenSocket.accept()
             req = Request(self.nameService, conn, addr)
             print("Serving a request from {0}".format(addr))
             req.start()
         except socket.error:
             print(socket.error)
             continue
         finally:
             pass

# -----------------------------------------------------------------------------
# The main program
# -----------------------------------------------------------------------------

if __name__ == "__main__":
    logging.info("NameServer listening to: {}:{}".format(
        server_address[0], server_address[1]))

    nameserver = NameServer()

    listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    listener.bind(("", server_address[1]))
    listener.listen(1)

    logging.info("Press Ctrl-C to stop the name server...")

    try:
        while True:
            conn, addr = listener.accept()
            req = Request(nameserver, conn, addr)
            logging.debug("NameServer serving a request from {}".format(addr))
            req.start()
            logging.debug("NameServer served the request from {}".format(addr))
    except KeyboardInterrupt:
        pass
    finally:
        listener.close()
        logging.info("NameServer has been unbound")
        finally:
            conn.send(result)

# -----------------------------------------------------------------------------
# The main program
# -----------------------------------------------------------------------------

if __name__ == "__main__":
    logging.info("NameServer listening to: {}:{}".format(server_address[0], server_address[1]))

    nameserver = NameServer()

    listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    listener.bind(("", server_address[1]))
    listener.listen(1)

    logging.info("Press Ctrl-C to stop the name server...")

    try:
        while True:
            conn, addr = listener.accept()
            req = Request(nameserver, conn, addr)
            logging.debug("NameServer serving a request from {}".format(addr))
            req.start()
            logging.debug("NameServer served the request from {}".format(addr))
    except KeyboardInterrupt:
        pass
    finally:
        listener.close()
        logging.info("NameServer has been unbound")