Table of Contents

Class: Protocol Twisted-0.19.0/twisted/internet/protocol.py

This is the abstract superclass of all protocols.

If you are going to write a new protocol for Twisted, start here. The docstrings of this class explain how you can get started. Any protocol implementation, either client or server, should be a subclass of me.

My API is quite simple. Implement dataReceived(data) to handle both event-based and synchronous input; output can be sent through the transport attribute, which is to be an instance of a twisted.protocols.protocol.Transport.

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

Methods   
connectionFailed
connectionLost
connectionMade
dataReceived
makeConnection
  connectionFailed 
connectionFailed ( self )

Called when a connection cannot be made.

This will only be called on client protocols; this message tells the protocol that the expected connection can not be made.

  connectionLost 
connectionLost ( self )

Called when the connection is shut down.

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

  connectionMade 
connectionMade ( self )

Called when a connection is made.

This may be considered the initializer of the protocol, because it is called when the connection is completed. For clients, this is called once the connection to the server has been established; for servers, this is called after an accept() call stops blocking and a socket has been received. If you need to send any greeting or initial message, do it here.

  dataReceived 
dataReceived ( self,  data )

Called whenever data is received.

data will be a string of indeterminate length. Please keep in mind that you will probably need to buffer some data, as partial protocol messages may be 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.

I recommend that unit tests for protocols call through to this method with differing chunk sizes, down to one byte at a time.

  makeConnection 
makeConnection ( self,  transport )

Make a connection to a transport and a server.

This sets the transport attribute of this Protocol, and calls the connectionMade() callback.


Table of Contents

This document was automatically generated on Sun Jul 14 19:52:41 2002 by HappyDoc version 2.0