Python 扭曲的HTTP/TCP协议

Python 扭曲的HTTP/TCP协议,python,twisted,Python,Twisted,我正在尝试创建一个twisted服务器,它将接受http post请求,然后将该post请求的信息写入tcp连接。现在,我刚刚修改了教程中给出的多回送服务器/客户端: from twisted.internet.protocol import Protocol, Factory from twisted.internet import reactor class MultiClientEcho(Protocol): def __init__(self, factory):

我正在尝试创建一个twisted服务器,它将接受http post请求,然后将该post请求的信息写入tcp连接。现在,我刚刚修改了教程中给出的多回送服务器/客户端:

from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor


class MultiClientEcho(Protocol):
    def __init__(self, factory):
        self.factory = factory

    def connectionMade(self):
        self.factory.clients.insert(self.factory.id, self)
        self.factory.id += 1
        self.ip = self.transport.getPeer()

    def dataReceived(self, data):
        self.factory.clients[0].transport.write(data)

    def connectionLost(self, reason):
        self.factory.clients.remove(self)


class MultiClientEchoFactory(Factory):
    def __init__(self):
        self.clients = []
        self.id = 0

    def buildProtocol(self, addr):
        return MultiClientEcho(self)


reactor.listenTCP(8000, MultiClientEchoFactory())
reactor.run()
我已经明白Twisted可以处理这类事情。如果是这样的话,有人能用一些代码或简单的例子给我指出正确的方向吗?我在这件事上撞到墙上已经有一段时间了


谢谢

你能澄清一下“写那篇文章的信息”是什么意思吗?你想写一个修改POST的HTTP代理,或者只是一个调试工具,通过在HTML中打印POST的变量来响应POST,或者其他一些东西?我真的想要一个可以同时处理多个协议的服务器,包括HTTP和tcp。我的意思是解析POST响应的表单数据或json对象,并通过tcp连接发送该信息。