t.i.p.Protocol(BaseProtocol) : class documentation

Part of twisted.internet.protocol View Source View In Hierarchy

Known subclasses: twisted.conch.client.agent.SSHAgentForwardingLocal, twisted.conch.insults.client.InsultsClient, twisted.conch.insults.helper.TerminalBuffer, twisted.conch.insults.insults.ClientProtocol, twisted.conch.insults.insults.ServerProtocol, twisted.conch.ssh.agent.SSHAgentClient, twisted.conch.ssh.agent.SSHAgentServer, twisted.conch.ssh.filetransfer.FileTransferBase, twisted.conch.ssh.forwarding.SSHForwardingClient, twisted.conch.ssh.session.SSHSessionClient, twisted.conch.ssh.transport.SSHTransportBase, twisted.conch.telnet.Telnet, twisted.conch.telnet.TelnetProtocol, twisted.internet._endpointspy3._WrappingProtocol, twisted.names.dns.DNSProtocol, twisted.protocols.basic.IntNStringReceiver, twisted.protocols.basic.LineOnlyReceiver, twisted.protocols.basic.LineReceiver, twisted.protocols.basic.NetstringReceiver, twisted.protocols.ftp.DTP, twisted.protocols.ftp.ProtocolWrapper, twisted.protocols.ftp.SenderProtocol, twisted.protocols.gps.rockwell.Zodiac, twisted.protocols.mice.mouseman.MouseMan, twisted.protocols.policies.ProtocolWrapper, twisted.protocols.portforward.Proxy, twisted.protocols.socks.SOCKSv4, twisted.protocols.socks.SOCKSv4Incoming, twisted.protocols.socks.SOCKSv4Outgoing, twisted.protocols.stateful.StatefulProtocol, twisted.protocols.telnet.Telnet, twisted.protocols.wire.Chargen, twisted.protocols.wire.Daytime, twisted.protocols.wire.Discard, twisted.protocols.wire.Echo, twisted.protocols.wire.QOTD, twisted.protocols.wire.Time, twisted.protocols.wire.Who, twisted.runner.inetd.InetdProtocol, twisted.spread.banana.Banana, twisted.web._newclient.HTTP11ClientProtocol, twisted.web.sux.XMLParser, twisted.words.protocols.irc.DccFileReceiveBasic, twisted.words.protocols.irc.DccSendProtocol, twisted.words.protocols.irc.IRC, twisted.words.protocols.oscar.OscarConnection, twisted.words.xish.xmlstream.XmlStream

Implements interfaces: twisted.internet.interfaces.ILoggingContext, twisted.internet.interfaces.IProtocol

This is the base class for streaming connection-oriented protocols.

If you are going to write a new connection-oriented protocol for Twisted, start here. Any protocol implementation, either client or server, should be a subclass of this class.

The API is quite simple. Implement dataReceived to handle both event-based and synchronous input; output can be sent through the 'transport' attribute, which is to be an instance that implements twisted.internet.interfaces.ITransport. Override connectionLost to be notified when the connection ends.

Some subclasses exist already to help you write common types of protocols: see the twisted.protocols.basic module for a few of them.

Method logPrefix Return a prefix matching the class name, to identify log messages related to this protocol instance.
Method dataReceived Called whenever data is received.
Method connectionLost Called when the connection is shut down.

Inherited from BaseProtocol:

Method makeConnection Make a connection to a transport and a server.
Method connectionMade Called when a connection is made.
def logPrefix(self): (source)
Return a prefix matching the class name, to identify log messages related to this protocol instance.
def dataReceived(self, data): (source)
overridden in twisted.conch.insults.client.InsultsClient, twisted.conch.insults.insults.ClientProtocol, twisted.conch.insults.insults.ServerProtocol, twisted.conch.ssh.agent.SSHAgentClient, twisted.conch.ssh.agent.SSHAgentServer, twisted.conch.ssh.filetransfer.FileTransferBase, twisted.conch.ssh.forwarding.SSHForwardingClient, twisted.conch.ssh.session.SSHSessionClient, twisted.conch.ssh.transport.SSHTransportBase, twisted.conch.telnet.Telnet, twisted.conch.telnet.TelnetBootstrapProtocol, twisted.internet._endpointspy3._WrappingProtocol, twisted.names.dns.DNSProtocol, twisted.protocols.basic.IntNStringReceiver, twisted.protocols.basic.LineOnlyReceiver, twisted.protocols.basic.LineReceiver, twisted.protocols.basic.NetstringReceiver, twisted.protocols.ftp.DTP, twisted.protocols.ftp.ProtocolWrapper, twisted.protocols.ftp.SenderProtocol, twisted.protocols.gps.rockwell.Zodiac, twisted.protocols.mice.mouseman.MouseMan, twisted.protocols.policies.ProtocolWrapper, twisted.protocols.portforward.Proxy, twisted.protocols.socks.SOCKSv4, twisted.protocols.socks.SOCKSv4Incoming, twisted.protocols.socks.SOCKSv4Outgoing, twisted.protocols.stateful.StatefulProtocol, twisted.protocols.telnet.Telnet, twisted.protocols.wire.Discard, twisted.protocols.wire.Echo, twisted.spread.banana.Banana, twisted.web._newclient.HTTP11ClientProtocol, twisted.web.sux.XMLParser, twisted.words.protocols.irc.DccFileReceiveBasic, twisted.words.protocols.irc.DccSendProtocol, twisted.words.protocols.irc.IRC, twisted.words.protocols.oscar.OscarConnection, twisted.words.xish.xmlstream.XmlStream
Called whenever data is received.

Use this method to translate to a higher-level message. Usually, some callback will be made upon the receipt of each complete protocol message.

Parametersdataa string of indeterminate length. Please keep in mind that you will probably need to buffer some data, as partial (or multiple) protocol messages may be received! I recommend that unit tests for protocols call through to this method with differing chunk sizes, down to one byte at a time.
def connectionLost(self, reason=connectionDone): (source)
overridden in twisted.conch.insults.insults.ClientProtocol, twisted.conch.insults.insults.ServerProtocol, twisted.conch.ssh.filetransfer.FileTransferServer, twisted.conch.ssh.forwarding.SSHForwardingClient, twisted.conch.ssh.transport.SSHTransportBase, twisted.conch.telnet.StatefulTelnetProtocol, twisted.conch.telnet.StatefulTelnetProtocol, twisted.conch.telnet.Telnet, twisted.conch.telnet.TelnetBootstrapProtocol, twisted.internet._endpointspy3._WrappingProtocol, twisted.mail.imap4.IMAP4Client, twisted.mail.imap4.IMAP4Server, twisted.mail.pop3.POP3, twisted.mail.pop3client.POP3Client, twisted.mail.smtp.SMTP, twisted.mail.smtp.SMTPClient, twisted.names.dns.DNSProtocol, twisted.protocols.amp.BinaryBoxProtocol, twisted.protocols.ftp.DTP, twisted.protocols.ftp.FTP, twisted.protocols.ftp.FTPClientBasic, twisted.protocols.ftp.ProtocolWrapper, twisted.protocols.ftp.SenderProtocol, twisted.protocols.ident.IdentClient, twisted.protocols.memcache.MemCacheProtocol, twisted.protocols.policies.ProtocolWrapper, twisted.protocols.portforward.Proxy, twisted.protocols.socks.SOCKSv4, twisted.protocols.socks.SOCKSv4Incoming, twisted.protocols.socks.SOCKSv4Outgoing, twisted.spread.pb.Broker, twisted.web._newclient.HTTP11ClientProtocol, twisted.web._newclient.HTTPClientParser, twisted.web.http.HTTPChannel, twisted.web.http.HTTPClient, twisted.web.sux.XMLParser, twisted.words.protocols.irc.DccFileReceive, twisted.words.protocols.irc.DccSendProtocol, twisted.words.protocols.irc.IRCClient, twisted.words.protocols.msn.FileReceive, twisted.words.protocols.msn.FileSend, twisted.words.protocols.msn.MSNEventBase, twisted.words.protocols.oscar.OscarConnection, twisted.words.service.IRCUser, twisted.words.xish.xmlstream.XmlStream
Called when the connection is shut down.

Clear any circular references here, and any external references to this Protocol. The connection has been closed.

API Documentation for Twisted, generated by pydoctor at 2012-12-26 12:18:15.