Twisted - kick特定客户端

时间:2012-04-13 16:39:04

标签: python client twisted

我想在基于扭曲的应用程序中断开特定用户。有人可以解释我怎么做吗?

1 个答案:

答案 0 :(得分: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()