<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.28.1">
</HEAD>
<BODY>
On Sat, 2010-02-06 at 17:13 +0000, exarkun@twistedmatrix.com wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
On 04:42 pm, <A HREF="mailto:darren@ontrenet.com">darren@ontrenet.com</A> wrote:
&gt;Hi,
&gt;  I have a simple protocol listening on a port. I send it a text message
&gt;(a filename)
&gt;and the protocol tries to stream back the bytes of the file. Mostly,
&gt;this works
&gt;but in some cases, the receiving side receives less bytes than is
&gt;written by:
&gt;
&gt;self.transport.write(bytes)
&gt;
&gt;I read the API which says it can receive less than expected bytes or
&gt;messages. Why?

That's how TCP works.  Bytes you send with one call to write may be 
split into two or more chunks and delivered to the remote dataReceived 
separately, or bytes you send with two or more calls to write may be 
combined into fewer chunks and delivered to the remote dataReceived all 
as one string.
</PRE>
</BLOCKQUOTE>
Yes, at the lower OSI layers it does. But in most modern programming languages,<BR>
the notion of an I/O stream is built atop it (e.g. sockets will recombine and order<BR>
the packets, but twisted does not?). So naturally, I don't want to emulate IP in<BR>
my Twisted app.<BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
<PRE>
&gt;
&gt;So how can I reliably send a sequences of bytes via &quot;dataReceived&quot; in 
&gt;my
&gt;protocol?

If you want &quot;framing&quot; - a byte format built on top of the basic 
functionality provided by TCP, allowing you to differentiate bytes 
belonging to different logical messages from each other - then you 
should take a look at some of the protocols in twisted.protocols.basic 
(NetstringReceiver, Int32StringReceiver, etc) or twisted.protocols.amp 
which expands on this idea to a much greater degree.
</PRE>
</BLOCKQUOTE>
Ok, cool. I thought this would be easier in Twisted, but I will research it more.
<BLOCKQUOTE TYPE=CITE>
<PRE>

You can read a lot more about these ideas in this series of articles by 
Itamar Turner-Trauring:

&nbsp; <A HREF="http://www.xml.com/pub/au/215">http://www.xml.com/pub/au/215</A>
</PRE>
</BLOCKQUOTE>
Thanks again.
<BLOCKQUOTE TYPE=CITE>
<PRE>

Jean-Paul

_______________________________________________
Twisted-Python mailing list
<A HREF="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</A>
<A HREF="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</A>
</PRE>
</BLOCKQUOTE>
<BR>
</BODY>
</HTML>