class Protocol(BaseProtocol): (source)
Known subclasses: twisted.conch.client.agent.SSHAgentForwardingLocal
, 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.conch.test.test_conch.ConchTestForwardingPort
, twisted.conch.test.test_conch.Echo
, twisted.conch.test.test_session.MockProtocol
, twisted.conch.test.test_ssh.CrazySubsystem
, twisted.internet.test.connectionmixins.ConnectableProtocol
, twisted.internet.test.test_endpoints.StubApplicationProtocol
, twisted.internet.test.test_endpoints.TestProtocol
, twisted.internet.test.test_tcp.FakeProtocol
, twisted.internet.test.test_tcp.StopStartReadingProtocol
, twisted.internet.test.test_win32serialport.CollectReceivedProtocol
, twisted.internet.testing.AccumulatingProtocol
, 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.haproxy.test.test_wrapper.StaticProtocol
, 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.test.test_tls.AccumulatingProtocol
, 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.test.process_twisted.Echo
, twisted.test.stdio_test_consumer.ConsumerChild
, twisted.test.stdio_test_halfclose.HalfCloseProtocol
, twisted.test.stdio_test_hostpeer.HostPeerChild
, twisted.test.stdio_test_lastwrite.LastWriteChild
, twisted.test.stdio_test_loseconn.LoseConnChild
, twisted.test.stdio_test_producer.ProducerChild
, twisted.test.stdio_test_write.WriteChild
, twisted.test.stdio_test_writeseq.WriteSequenceChild
, twisted.test.test_amp.TestProto
, twisted.test.test_amp.TotallyDumbProtocol
, twisted.test.test_ftp.PrintLines
, twisted.test.test_internet.MyProtocol
, twisted.test.test_loopback.LoopbackRelayTest.Receiver
, twisted.test.test_policies.EchoProtocol
, twisted.test.test_policies.SimpleProtocol
, twisted.test.test_policies.TimeoutTester
, twisted.test.test_ssl.ImmediatelyDisconnectingProtocol
, twisted.test.test_ssl.RecordingClientProtocol
, twisted.test.test_ssl.SingleLineServerProtocol
, twisted.test.test_sslverify.DataCallbackProtocol
, twisted.test.test_sslverify.WritingProtocol
, twisted.test.test_tcp.ClosingProtocol
, twisted.test.test_tcp.ConnectionLosingProtocol
, twisted.test.test_tcp.ConnectionLostNotifyingProtocol
, twisted.test.test_tcp.LargeBufferReaderProtocol
, twisted.test.test_tcp.LargeBufferWriterProtocol
, twisted.test.test_tcp.NoopProtocol
, twisted.test.test_tcp.ReaderProtocol
, twisted.test.test_tcp.WriterProtocol
, twisted.test.test_tpfile.BufferingServer
, twisted.test.test_tpfile.FileSendingClient
, twisted.web._http2.H2Connection
, twisted.web._newclient.HTTP11ClientProtocol
, twisted.web.sux.XMLParser
, twisted.web.test.test_agent.SimpleAgentProtocol
, twisted.web.test.test_agent.StubHTTPProtocol
, twisted.words.protocols.irc.DccFileReceiveBasic
, twisted.words.protocols.irc.DccSendProtocol
, twisted.words.protocols.irc.IRC
, twisted.words.test.test_xmlstream.DummyProtocol
, twisted.words.xish.xmlstream.XmlStream
, twisted.internet.endpoints._WrappingProtocol
, twisted.test.test_ftp._BufferingProtocol
, twisted.web.client._ReadBodyProtocol
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 | connection |
Called when the connection is shut down. |
Method | data |
Called whenever data is received. |
Method | log |
Return a prefix matching the class name, to identify log messages related to this protocol instance. |
Class Variable | factory |
Undocumented |
Inherited from BaseProtocol
:
Method | connection |
Called when a connection is made. |
Method | make |
Make a connection to a transport and a server. |
Instance Variable | connected |
Undocumented |
Instance Variable | transport |
Undocumented |
twisted.conch.insults.insults.ClientProtocol
, twisted.conch.insults.insults.ServerProtocol
, twisted.conch.ssh.filetransfer.FileTransferBase
, 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.conch.test.test_conch.ConchTestForwardingPort
, twisted.conch.test.test_conch.Echo
, twisted.conch.test.test_recvline.NotifyingExpectableBuffer
, twisted.conch.test.test_session.MockProtocol
, twisted.internet.test.connectionmixins.ConnectableProtocol
, twisted.internet.test.test_endpoints.StubApplicationProtocol
, twisted.internet.test.test_endpoints.TestProtocol
, twisted.internet.testing.AccumulatingProtocol
, twisted.internet.testing.LineSendingProtocol
, twisted.mail.imap4.IMAP4Client
, twisted.mail.imap4.IMAP4Server
, twisted.mail.pop3.AdvancedPOP3Client
, twisted.mail.pop3.POP3
, 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.protocols.test.test_tls.AccumulatingProtocol
, twisted.spread.pb.Broker
, twisted.test.process_twisted.Echo
, twisted.test.stdio_test_consumer.ConsumerChild
, twisted.test.stdio_test_halfclose.HalfCloseProtocol
, twisted.test.stdio_test_hostpeer.HostPeerChild
, twisted.test.stdio_test_lastwrite.LastWriteChild
, twisted.test.stdio_test_loseconn.LoseConnChild
, twisted.test.stdio_test_producer.ProducerChild
, twisted.test.stdio_test_write.WriteChild
, twisted.test.stdio_test_writeseq.WriteSequenceChild
, twisted.test.test_amp.TestProto
, twisted.test.test_application.Foo
, twisted.test.test_application.TestEcho
, twisted.test.test_loopback.SimpleProtocol
, twisted.test.test_policies.SimpleProtocol
, twisted.test.test_policies.TimeoutTester
, twisted.test.test_ssl.ImmediatelyDisconnectingProtocol
, twisted.test.test_ssl.LineCollector
, twisted.test.test_ssl.UnintelligentProtocol
, twisted.test.test_sslverify.DataCallbackProtocol
, twisted.test.test_sslverify.WritingProtocol
, twisted.test.test_stateful.TestInt32
, twisted.test.test_tcp.ClosingProtocol
, twisted.test.test_tcp.ConnectionLostNotifyingProtocol
, twisted.test.test_tcp.LargeBufferReaderProtocol
, twisted.test.test_tcp.NoopProtocol
, twisted.test.test_tcp.ReaderProtocol
, twisted.web._http2.H2Connection
, twisted.web._newclient.HTTP11ClientProtocol
, twisted.web._newclient.HTTPClientParser
, twisted.web.http.HTTPChannel
, twisted.web.http.HTTPClient
, twisted.web.sux.XMLParser
, twisted.web.test.test_agent.SimpleAgentProtocol
, twisted.words.protocols.irc.DccFileReceive
, twisted.words.protocols.irc.DccSendProtocol
, twisted.words.protocols.irc.IRCClient
, twisted.words.service.IRCUser
, twisted.words.xish.xmlstream.XmlStream
, twisted.internet.endpoints._WrappingProtocol
, twisted.test.test_ftp._BufferingProtocol
, twisted.web.client._ReadBodyProtocol
Called when the connection is shut down.
Clear any circular references here, and any external references to this Protocol. The connection has been closed.
Parameters | |
reason:twisted.python.failure.Failure | Undocumented |
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.conch.test.test_conch.ConchTestForwardingPort
, twisted.conch.test.test_conch.Echo
, twisted.conch.test.test_session.MockProtocol
, twisted.internet.test.connectionmixins.ClosingLaterProtocol
, twisted.internet.test.test_endpoints.StubApplicationProtocol
, twisted.internet.test.test_endpoints.TestProtocol
, twisted.internet.test.test_tcp.AbortingClient
, twisted.internet.test.test_tcp.EventualNoReadServer
, twisted.internet.test.test_tcp.FakeProtocol
, twisted.internet.test.test_tcp.ProducerAbortingClientLater
, twisted.internet.test.test_tcp.ReadAbortServerProtocol
, twisted.internet.test.test_tcp.ServerAbortsThenLoses
, twisted.internet.test.test_tcp.ServerAbortsTwice
, twisted.internet.test.test_tcp.StopStartReadingProtocol
, twisted.internet.test.test_tcp.StreamingProducerClientLater
, twisted.internet.test.test_unix.ReceiveFileDescriptor
, twisted.internet.test.test_win32serialport.CollectReceivedProtocol
, twisted.internet.testing.AccumulatingProtocol
, 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.haproxy.test.test_wrapper.StaticProtocol
, 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.test.test_tls.AccumulatingProtocol
, twisted.protocols.wire.Discard
, twisted.protocols.wire.Echo
, twisted.spread.banana.Banana
, twisted.test.process_twisted.Echo
, twisted.test.stdio_test_producer.ProducerChild
, twisted.test.test_amp.TestProto
, twisted.test.test_amp.TotallyDumbProtocol
, twisted.test.test_loopback.LoopbackRelayTest.Receiver
, twisted.test.test_policies.EchoProtocol
, twisted.test.test_policies.SimpleProtocol
, twisted.test.test_policies.TimeoutTester
, twisted.test.test_ssl.RecordingClientProtocol
, twisted.test.test_sslverify.DataCallbackProtocol
, twisted.test.test_tcp.LargeBufferReaderProtocol
, twisted.test.test_tcp.ReaderProtocol
, twisted.test.test_tpfile.BufferingServer
, twisted.web._http2.H2Connection
, twisted.web._newclient.HTTP11ClientProtocol
, twisted.web.sux.XMLParser
, twisted.web.test.test_agent.SimpleAgentProtocol
, twisted.words.protocols.irc.DccFileReceiveBasic
, twisted.words.protocols.irc.DccSendProtocol
, twisted.words.protocols.irc.IRC
, twisted.words.xish.xmlstream.XmlStream
, twisted.internet.endpoints._WrappingProtocol
, twisted.test.test_ftp._BufferingProtocol
, twisted.web.client._ReadBodyProtocol
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.
Parameters | |
data:bytes | a 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. |
twisted.internet.test.test_endpoints.TestProtocol
, twisted.protocols.policies.ProtocolWrapper
, twisted.internet.endpoints._WrappingProtocol
Return a prefix matching the class name, to identify log messages related to this protocol instance.
twisted.conch.client.direct.SSHClientTransport
, twisted.conch.insults.insults.ClientProtocol
, twisted.conch.insults.insults.ServerProtocol
, twisted.conch.test.test_userauth.FakeTransport
, twisted.internet.testing.AccumulatingProtocol
, twisted.mail.pop3.POP3
, twisted.mail.relaymanager.SMTPManagedRelayer
, twisted.protocols.policies.ProtocolWrapper
, twisted.spread.pb.Broker
, twisted.test.test_amp.FactoryNotifier
, twisted.web._http2.H2Connection
Undocumented