【发布时间】:2012-09-30 07:46:14
【问题描述】:
我正在尝试学习 python 扭曲的互联网框架,但有一件事让我感到困惑。使用 telnet 进行的初始测试表明,只要接收到数据,就会调用 protocol.Protocol.dataReceived() 方法。因此,如果我将其定义如下,它会在触发前等待 EOL:
def dataReceived(self, data):
print "MyProtocol::dataReceived, (%s)" %(data)
输出:
MyProtocol::dataReceived, (dgdfg
)
但是,只要我添加了额外的一行:
def dataReceived(self, data):
print "MyProtocol::dataReceived, (%s)" %(data)
self.transport.write(data)
它会为每个角色触发。
输出:
MyProtocol::dataReceived, (d)
MyProtocol::dataReceived, (g)
MyProtocol::dataReceived, (d)
MyProtocol::dataReceived, (f)
MyProtocol::dataReceived, (g)
MyProtocol::dataReceived, (
)
对这里发生的事情有什么想法吗?
工厂是protocol.Factory,协议是protocol.Protocol
谢谢
【问题讨论】: