关于Twisted Documents

时间:2011-07-21 05:21:59

标签: python twisted

我是Twisted的初学者。最近,我正在阅读“Twisted Network Programming Essentials”一书。例2-3在本书中如下:

class QuickDisconnectProtocol(protocol.Protocol): 

def connectionMade(self): 

    print "Connected to %s." % self.transport.getPeer( ).host 

    self.transport.loseConnection( ) 

==================================

self.transport.loseConnection( )

会员“运输”在哪里? 我在协议中找不到那个。

关于Ex2-4的同样问题......

有没有人知道如何阅读Twisted Documents?谢谢!

1 个答案:

答案 0 :(得分:1)

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,文件等。搜索transport的在线API文档并查看ie

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)时使用其中一个,当您这样做时,会变为协议的属性。