Changes between Version 26 and Version 27 of FrequentlyAskedQuestions


Ignore:
Timestamp:
02/13/09 12:52:53 (13 years ago)
Author:
Glyph
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FrequentlyAskedQuestions

    v26 v27  
    107107reactor.run()
    108108}}}
     109
     110=== Why is `protocol.dataReceived` called with only part of the data I called `transport.write` with? ===
     111
     112TCP is a stream-oriented transport.  This means that when you call `transport.write`, the data may be broken up into arbitrarily-sized chunks for transmission over the network.  There is no way for Twisted to determine how large the data originally written to the transport was.
     113
     114If you want to send a message and receive it whole on the other end of a connection, you must decide on a format for the message and parse it.  For example, prefixing the message with a length or terminating it with a message boundary.  Luckily, Twisted provides many different utilities for this purpose, which can automatically divide the data stream into messages for you:
     115
     116  * [http://twistedmatrix.com/documents/8.2.0/api/twisted.protocols.basic.LineReceiver.html LineReceiver]
     117  * [http://twistedmatrix.com/documents/8.2.0/api/twisted.protocols.basic.NetstringReceiver.html NetstringReceiver]
     118  * [http://twistedmatrix.com/documents/8.2.0/api/twisted.protocols.basic.Int16StringReceiver.html Int16StringReceiver]
     119
     120These are implemented as classes you inherit from rather than `Protocol`, and implement methods other than `dataReceived` (such as `stringReceived` or `lineReceived`).  You may also want to consider a higher-level messaging protocol, to exchange messages with more structure than a simple collection of bytes.  For example, the [http://twistedmatrix.com/documents/8.2.0/api/twisted.protocols.amp.html Asynchronous Messaging Protocol], or [http://twistedmatrix.com/projects/core/documentation/howto/pb-intro.html Perspective Broker].
    109121
    110122=== Why isn't my `connectionLost` method called? ===