我是Twisted的初学者。最近,我正在阅读本书中的“扭曲网络编程要领”.The Example 2-3,如下所示:
class QuickDisconnectProtocol(protocol.Protocol):
def connectionMade(self):
print "Connected to %s." % self.transport.getPeer( ).host
self.transport.loseConnection( ) ==================================
self.transport.loseConnection( )
"transport“在哪里?我在协议里找不到这个。
当涉及EX2-4时,同样的问题...
有人知道如何阅读Twisted文档吗?谢谢!
发布于 2011-07-21 13:46:47
def makeConnection(self, transport): ([source][1])
"""
overridden in twisted.protocols.amp.BinaryBoxProtocol,
twisted.protocols.ftp.ProtocolWrapper, twisted.protocols.ftp.SenderProtocol,
twisted.protocols.policies.ProtocolWrapper,
twisted.protocols.stateful.StatefulProtocol`
Make a connection to a transport and a server.
This sets the 'transport' attribute of this Protocol, and calls the connectionMade()
callback.
"""传输是到您正在使用的任何东西的连接,比如telnet、SSH、文件等。在在线API文档中搜索transport并查看。
http://twistedmatrix.com/documents/8.2.0/api/twisted.conch.ssh.transport.SSHTransportBase.html
下面是一些现有的传输,来自http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.interfaces.ITransport.html
Known subclasses: twisted.conch.insults.insults.ITerminalTransport,
twisted.conch.telnet.ITelnetTransport, twisted.internet.interfaces.IProcessTransport,
twisted.internet.interfaces.ITCPTransport
Known implementations: twisted.conch.ssh.channel.SSHChannel,
twisted.internet._posixstdio.StandardIO, twisted.internet._win32stdio.StandardIO,
twisted.internet.abstract.FileDescriptor, twisted.internet.iocpreactor.abstract.FileHandle,
twisted.internet.protocol.FileWrapper, twisted.protocols.loopback._LoopbackTransport,
twisted.protocols.loopback.LoopbackRelay根据您想要连接到的位置,当您调用makeConnection(transport)时使用其中一个,当您这样做时,它的变成了协议的一个属性。
https://stackoverflow.com/questions/6771582
复制相似问题