首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关于扭曲文档

关于扭曲文档
EN

Stack Overflow用户
提问于 2011-07-21 13:21:59
回答 1查看 508关注 0票数 1

我是Twisted的初学者。最近,我正在阅读本书中的“扭曲网络编程要领”.The Example 2-3,如下所示:

代码语言:javascript
复制
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文档吗?谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-21 13:46:47

代码语言:javascript
复制
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

代码语言:javascript
复制
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)时使用其中一个,当您这样做时,它的变成了协议的一个属性。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6771582

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档