【发布时间】:2015-02-03 23:55:59
【问题描述】:
我正在尝试编写一个代理服务器来做一些事情:
- 从客户端接收数据。
- 验证数据。
- 将数据转发到服务器。
- 从服务器
immediately接收数据发送回客户端。
在node.js 中,我可以使用server.pipe(client) 执行#4。扭曲中有没有类似的技巧?
我有什么:
class Player(protocol.Protocol):
def __init__(self):
self.server_connection = reactor.connectTCP('192.168.254.101', 1000, GateFactory())
...
class Gate(protocol.Protocol):
def dataReceived(self, recd):
print recd
...
class GateFactory(protocol.ClientFactory):
def buildProtocol(self):
return Gate()
...
class PlayerFactory(protocol.Factory):
def __init__(self):
self.players = {}
def buildProtocol(self, addr):
return Player(self.players)
...
reactor.listenTCP(1000, PlayerFactory())
我的问题
我通过以下方式将数据转发到服务器:
self.gate_connection.transport.write(packet)
但是我如何将响应转发给客户端:
class Gate(protocol.Protocol):
def dataReceived(self, recd):
print recd
【问题讨论】:
标签: python python-2.7 proxy twisted