<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>rel=me &#187; flush</title>
	<atom:link href="http://rel.me/t/flush/feed/" rel="self" type="application/rss+xml" />
	<link>http://rel.me</link>
	<description>programming, objective-c, cocoa, iphone, c</description>
	<lastBuildDate>Wed, 01 Feb 2012 07:26:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Flush</title>
		<link>http://rel.me/2007/12/27/flush/</link>
		<comments>http://rel.me/2007/12/27/flush/#comments</comments>
		<pubDate>Thu, 27 Dec 2007 05:22:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[flush]]></category>
		<category><![CDATA[socket]]></category>

		<guid isPermaLink="false">/2008/03/04/flush</guid>
		<description><![CDATA[So I decided to try to overcome the Leopard File.upload() bug by rolling my own http client: as3httpclientlib which even supports https with the TLS (Socket) support from as3crypto (which is great). The HTTP protocol is pretty simple and I figured it would be a good way to learn the internals and look smart reading [...]]]></description>
			<content:encoded><![CDATA[<p>So I decided to try to overcome the Leopard File.upload() <a href="http://www.google.com/search?q=flash+leopard+file+upload">bug</a> by rolling my own http client: <a href="http://code.google.com/p/as3httpclientlib/">as3httpclientlib</a> which even supports https with the TLS (Socket) support from <a href="http://crypto.hurlant.com/">as3crypto</a> (which is great). The HTTP protocol is pretty simple and I figured it would be a good way to learn the internals and look smart reading ancient <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC</a>&#8216;s. All you need is a Socket class and nice, flash api has one at <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/Socket.html">flash.net.Socket<br />
</a></p>
<p>I got everything major working like GET, PUT and POST with multipart/form-data and reading chunked encoding and all that stuff. Not too hard since there are open source http libraries for every major language. I looked at ruby <a href="http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html">Net::HTTP</a> (stole some regex&#8217;s) and <a href="http://hc.apache.org/httpclient-3.x/">Apache Httpclient</a> (stole your multipart boundary).</p>
<p>I got to the point where I was testing uploading larger files, like in:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript"><span class="kw2">var</span> client:HttpClient = <span class="kw2">new</span> HttpClient<span class="br0">&#40;</span><span class="br0">&#41;</span>;
<span class="kw2">var</span> uri:URI = <span class="kw2">new</span> URI<span class="br0">&#40;</span><span class="st0">&quot;http://mybucket.s3.amazonaws.com/big.mp3&quot;</span><span class="br0">&#41;</span>;
<span class="kw2">var</span> testFile:File = <span class="kw2">new</span> File<span class="br0">&#40;</span><span class="st0">&quot;app:/test/assets/big.mp3&quot;</span><span class="br0">&#41;</span>;
client.<span class="me1">upload</span><span class="br0">&#40;</span>uri, testFile<span class="br0">&#41;</span>;</pre></div></div>

<p>It turns out that when you call <tt>_socket.flush()</tt> (in <a href="http://as3httpclientlib.googlecode.com/svn/trunk/src/org/httpclient/HttpSocket.as">HttpSocket</a>) it doesn&#8217;t actually block, which you might expect. After thinking on it, this isn&#8217;t totally shocking since the whole threading model behind actionscript, you don&#8217;t really ever block (like there is no such thing as a modal dialog in flash). The problem is without blocking or an event to notify of a flush, the socket just gets filled with the request body all at once (all 800MB&#8217;s or whatever file size). </p>
<p>It turns out other people ran into this as well. If you look at (<a href="http://maliboo.pl/projects/FlexFTP/">FlexFTP</a>) source, the UploadInv.as file, you will see block of code commented out and replaced by a setInterval(.. , 300). Nice. I guess that upload is capped at ~12kb/sec.</p>
<p>Any of the links in the comments off this <a href="http://www.onflex.org/ted/2007/05/flexftp-ftp-client-in-flex-using.php">blog post</a> are useful too.</p>
<p>If you look at FileStream object you will see it has an <a href="http://livedocs.adobe.com/labs/flex3/langref/flash/filesystem/FileStream.html#event:outputProgress">outputProgressEvent</a> so that would be useful, you know, if Socket had that too.</a></p>
<p>I don&#8217;t know how you get around this issue, other than trying to guess how fast the socket can transmit and try to stay under that. So now I&#8217;m not sure what to do, other than abandon it and come back to it when its fixed, which hopefully will be soon. Thankfully, I can go back to ruby and maybe play with some <a href="http://rubycocoa.sourceforge.net/HomePage">RubyCocoa</a> or <a href="http://code.whytheluckystiff.net/shoes/">Shoes</a> framework.</p>
<p><strong>Update</strong>: Feel free to chime in at <a href="http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=72&#038;catid=641&#038;threadid=1325579&#038;enterthread=y">Adobe Air Forum</a> or <a href="http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform">Feature Request/Bug Report Form</a></p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/12/27/flush/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

