0

I want to disconnect specific user in twisted based application. Can somebody explain how I can do it ?

4

1 に答える 1

1
from twisted.web import server, resource
from twisted.internet import reactor

bannedIPs = ["127.0.0.1"]

class HelloResource(resource.Resource):
    isLeaf = True
    numberRequests = 0

    def render_GET(self, request):
        clientIP = request.getClientIP()

        if clientIP in bannedIPs:
            return "you are banned"

        self.numberRequests += 1
        request.setHeader("content-type", "text/plain")
        return "I am request #" + str(self.numberRequests) + "\n"

reactor.listenTCP(8080, server.Site(HelloResource()))
reactor.run()
于 2012-04-15T15:03:33.290 に答える