<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Madarco DevBlog</title>
	
	<link>http://blog.madarco.net</link>
	<description>on Flash, Java, Webdesign</description>
	<pubDate>Thu, 14 Aug 2008 15:23:56 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/MadarcoDevblog" type="application/rss+xml" /><item>
		<title>Populate - Real time site traffic</title>
		<link>http://feeds.feedburner.com/~r/MadarcoDevblog/~3/364858282/</link>
		<comments>http://blog.madarco.net/87/populate-real-time-site-traffic/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 15:03:26 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/?p=87</guid>
		<description><![CDATA[Today I&#8217;m stumbled upon this interesting site that shows the activity of the net in real time.
Every time someone visit a site a flash light on the map.

Everyone can subscribe to this service: just put a link in your homepage to see the real time traffic of your site on a world map.
The collected data [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;m stumbled upon this interesting site that shows the activity of the net in real time.</p>
<p>Every time someone visit a site a flash light on the map.<br />
<span id="more-87"></span></p>
<p>Everyone can subscribe to this service: just put a link in your homepage to see the real time traffic of your site on a world map.<br />
The collected data of all the participating websites will show on the collective map.</p>
<p><a href="http://www.populatetheweb.com/who_populates_map.php">Populate - Real time site traffic</a><br />
<a href="http://www.populatetheweb.com/who_populates_map.php?s=blog.madarco.net">See my web traffic</a></p>
<img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/364858282" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/87/populate-real-time-site-traffic/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.madarco.net/87/populate-real-time-site-traffic/</feedburner:origLink></item>
		<item>
		<title>Flash 10 will support P2P network and UDP</title>
		<link>http://feeds.feedburner.com/~r/MadarcoDevblog/~3/326507106/</link>
		<comments>http://blog.madarco.net/85/flash-10-will-support-p2p-network-and-udp/#comments</comments>
		<pubDate>Fri, 04 Jul 2008 09:18:34 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/?p=85</guid>
		<description><![CDATA[Great news for multiplayer flash games!
In the latest beta release of Flash Player 10, Adobe introduced the RTMFP support.
In short this technology will allow P2P communication between players and UDP:
Direct (P2P) communication between Flash players.
Every flash application will be able to connect to another without going through a server, saving bandwidth and lowering latency.
A Flash [...]]]></description>
			<content:encoded><![CDATA[<p>Great news for multiplayer flash games!<br />
In the latest beta release of Flash Player 10, Adobe introduced the <strong>RTMFP</strong> support.<br />
In short this technology will allow P2P communication between players and UDP:</p>
<h3>Direct (P2P) communication between Flash players.</h3>
<p>Every flash application will be able to connect to another without going through a server, saving bandwidth and lowering latency.<br />
A Flash Media Server will be required to establish the connection between players.</p>
<h3>UDP communication with a server</h3>
<p>The next version of Flash Media Server (and maybe of Red5) will allow audio and video streaming from and to the flash player over the UDP, which is a more efficient way to deliver low latency packets.<br />
Applications like Skype and the majority of multiplayer games already use that with obvious advantages.</p>
<p>Further informations:<br />
<a href="http://download.macromedia.com/pub/labs/flashplayer10/flashplayer10_rtmfp_faq_070208.pdf">RTMFP FAQ</a><br />
<a href="http://labs.adobe.com/technologies/flashplayer10/releasenotes.html#features_rm">Flash Player 10 Release notes</a><br />
<a href="http://en.wikipedia.org/wiki/User_datagram_protocol">UDP Wikipedia entry</a></p>
<img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/326507106" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/85/flash-10-will-support-p2p-network-and-udp/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.madarco.net/85/flash-10-will-support-p2p-network-and-udp/</feedburner:origLink></item>
		<item>
		<title>Must see: 3D desktop application</title>
		<link>http://feeds.feedburner.com/~r/MadarcoDevblog/~3/237059669/</link>
		<comments>http://blog.madarco.net/83/whitevoid-3d-desktop/#comments</comments>
		<pubDate>Mon, 18 Feb 2008 16:54:55 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
		
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/83/whitevoid-3d-desktop/</guid>
		<description><![CDATA[Today I&#8217;ve stumbled upon this wonderful 3d desktop application:

WHITEvoid portfolio application

Remembered me of the 3D desktop concept video &#8220;Bumptop&#8221;:


]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;ve stumbled upon this wonderful 3d desktop application:<br />
<a href='http://blog.madarco.net/wp-content/uploads/whitevoid.JPG' title='3d desktop portfolio'><img src='http://blog.madarco.net/wp-content/uploads/whitevoid.thumbnail.JPG' alt='3d desktop portfolio' /><br />
WHITEvoid portfolio application<br />
</a><br />
Remembered me of the 3D desktop concept video &#8220;Bumptop&#8221;:<br />
<a href='http://www.bumptop.com/' title='Bumptop'><br />
<img src='http://blog.madarco.net/wp-content/uploads/bumptop.thumbnail.jpg' alt='Bumptop' /></a></p>
<img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/237059669" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/83/whitevoid-3d-desktop/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.madarco.net/83/whitevoid-3d-desktop/</feedburner:origLink></item>
		<item>
		<title>haxeVideo</title>
		<link>http://feeds.feedburner.com/~r/MadarcoDevblog/~3/201143315/</link>
		<comments>http://blog.madarco.net/81/haxevideo/#comments</comments>
		<pubDate>Sun, 16 Dec 2007 11:47:55 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
		
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/81/haxevideo/</guid>
		<description><![CDATA[Only a day after the release of BlazeDS, Nicolas Cannasse (Motion-Twin) has just released haxeVideo:

haxeVideo is an opensource video streaming server entirely written in haXe
Features include :
    * FLV streaming using RTMP protocol
    * Webcam and Microphone recording to FLV file
    * Live streaming for web [...]]]></description>
			<content:encoded><![CDATA[<p>Only a day after the release of BlazeDS, Nicolas Cannasse (<a href="http://www.motion-twin.com/">Motion-Twin</a>) has <a href="http://blog.haxe.org/entry/28">just released</a> <strong><a href="http://haxevideo.org/">haxeVideo</a></strong>:</p>
<blockquote><p>
haxeVideo is an opensource video streaming server entirely written in haXe<br />
Features include :</p>
<p>    * FLV streaming using RTMP protocol<br />
    * Webcam and Microphone recording to FLV file<br />
    * Live streaming for web conferencing<br />
    * light and fast scalable server<br />
    * only 50 KB of server source code : modify whatever you need !
</p></blockquote>
<p>Finally the multiuser/conferencing thing is taking place?<br />
We will ever see affordable (T)RTMP hosting services?</p>
<p>PS: This can be the right answer to those interested in a <a href="http://blog.madarco.net/44/memory-leaks-playing-shoutcasticecast-streams-in-flash/">web-radio solution<br />
</a></p>
<img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/201143315" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/81/haxevideo/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.madarco.net/81/haxevideo/</feedburner:origLink></item>
		<item>
		<title>A dream come true: AMF3 specs and BlazeDS</title>
		<link>http://feeds.feedburner.com/~r/MadarcoDevblog/~3/200341195/</link>
		<comments>http://blog.madarco.net/80/a-dream-come-true-amf3-specs-and-blazeds/#comments</comments>
		<pubDate>Fri, 14 Dec 2007 15:32:54 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
		
		<category><![CDATA[Flash]]></category>

		<category><![CDATA[General]]></category>

		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/80/a-dream-come-true-amf3-specs-and-blazeds/</guid>
		<description><![CDATA[This week were released:
 AMF3 specification
Action Message Format (AMF) is a compact binary format that is used to
ActionScript object graphs. Once serialized an AMF encoded object graph
to persist and retrieve the public state of an application across sessions or
endpoints to communicate through the exchange of strongly typed data.
And Java-Remoting BlazeDS Beta
BlazeDS is the server-based Java [...]]]></description>
			<content:encoded><![CDATA[<p>This week were released:<br />
 <strong><a href="http://labs.adobe.com/technologies/blazeds/">AMF3 specification</a></strong></p>
<blockquote><p>Action Message Format (AMF) is a compact binary format that is used to<br />
ActionScript object graphs. Once serialized an AMF encoded object graph<br />
to persist and retrieve the public state of an application across sessions or<br />
endpoints to communicate through the exchange of strongly typed data.</p></blockquote>
<p>And <strong><a href="http://labs.adobe.com/technologies/blazeds/">Java-Remoting BlazeDS Beta</a></strong></p>
<blockquote><p>BlazeDS is the server-based Java remoting and web messaging technology that enables developers to easily connect to back-end distributed data and push data in real-time to Adobe Flex and Adobe AIR applications for more responsive rich Internet application (RIA) experiences.</p>
<p>Previously available only as part of Adobe LiveCycle Data Services ES, Adobe is announcing its plans to contribute the proven BlazeDS technologies to the community under the LGPL v3. BlazeDS gives the rapidly growing Adobe developer community free access to the powerful remoting and messaging technologies developed by Adobe.</p>
<p>The source code will be available for download in early 2008.</p></blockquote>
<p>In short: more AMF servers for free, other than <a href="http://osflash.org/red5">RED5</a></p>
<img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/200341195" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/80/a-dream-come-true-amf3-specs-and-blazeds/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.madarco.net/80/a-dream-come-true-amf3-specs-and-blazeds/</feedburner:origLink></item>
		<item>
		<title>Blog hacked: Phentermine Attack</title>
		<link>http://feeds.feedburner.com/~r/MadarcoDevblog/~3/199923276/</link>
		<comments>http://blog.madarco.net/79/phentermine-attack/#comments</comments>
		<pubDate>Thu, 13 Dec 2007 20:24:40 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/79/phentermine-attack/</guid>
		<description><![CDATA[I&#8217;ve not blogged too much lately, however, there was some strange &#8220;activities&#8221; on my blog&#8230;
Today someone in a comment warned me that I have some spam links in the footer visible only with javascripts disabled.
I&#8217;ve updated wordpress some days ago because I&#8217;ve noticed some spam links in my sidebar, but as it seems this wasn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve not blogged too much lately, however, there was some strange &#8220;activities&#8221; on my blog&#8230;</p>
<p>Today someone in <a href="/78/the-doom-game-in-flash/#comment-20288">a comment</a> warned me that I have some spam links in the footer visible only with <strong>javascripts disabled</strong>.</p>
<p>I&#8217;ve updated wordpress some days ago because I&#8217;ve noticed some spam links in my sidebar, but as it seems this wasn&#8217;t enough to fix the problem.</p>
<p>Luckily, I&#8217;m using <a href="http://subversion.tigris.org/">subversion</a> to manage wordpress updates, in this way I can see what happened to my wordpress:<br />
<code><br />
?                   wp-includes/class-mail.php<br />
M            6377   wp-includes/default-filters.php<br />
M            6377   wp-includes/wp-db.php<br />
M            6377   wp-includes/gettext.php<br />
M            6377   wp-includes/pluggable.php<br />
M            6377   xmlrpc.php<br />
M            6377   index.php<br />
M            6377   wp-admin/admin.php<br />
M            6377   wp-admin/index.php<br />
</code></p>
<p>There was a new file <code>class-mail.php</code> and the others were modified.<br />
Luckily nothing that a few <code>svn revert</code> commands couldn&#8217;t heal <img src='http://blog.madarco.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>If you want to check if you blog has the same &#8220;guest&#8221; links:</p>
<ol>
<li> disable javascripts</li>
<li>look at your footer.</li>
</ol>
<p>If so:</p>
<ol>
<li>replace those files marked with M</li>
<li>delete class-mail.php</li>
</ol>
<p>More info on this exploit: <a href="http://wordpress.org/support/topic/123108/page/2">Phentermine attack</a><br />
This episode is the proof of how useful is to install/update wordpress with subversion: <a href="http://codex.wordpress.org/Installing/Updating_WordPress_with_Subversion">Install wordpress with subversion</a></p>
<img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/199923276" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/79/phentermine-attack/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.madarco.net/79/phentermine-attack/</feedburner:origLink></item>
		<item>
		<title>The Doom game in Flash</title>
		<link>http://feeds.feedburner.com/~r/MadarcoDevblog/~3/140594486/</link>
		<comments>http://blog.madarco.net/78/the-doom-game-in-flash/#comments</comments>
		<pubDate>Sat, 04 Aug 2007 10:35:37 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
		
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/78/the-doom-game-in-flash/</guid>
		<description><![CDATA[The Doom game in flash:
This uses the original Doom shareware wad file and gets all content from it at runtime. 
See it here: Flash Doom game
]]></description>
			<content:encoded><![CDATA[<p><strong>The Doom</strong> game in flash:</p>
<blockquote><p>This uses the original Doom shareware wad file and gets all content from it at runtime. </p></blockquote>
<p>See it here: <a href="http://blog.brokenfunction.com/2007/07/20/flash-plays-doom/">Flash Doom game</a></p>
<img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/140594486" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/78/the-doom-game-in-flash/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.madarco.net/78/the-doom-game-in-flash/</feedburner:origLink></item>
		<item>
		<title>Zoomquilt 2</title>
		<link>http://feeds.feedburner.com/~r/MadarcoDevblog/~3/124031120/</link>
		<comments>http://blog.madarco.net/77/zoomquilt-2/#comments</comments>
		<pubDate>Mon, 11 Jun 2007 21:37:21 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/77/zoomquilt-2/</guid>
		<description><![CDATA[Must be blogged: The collaborative Zoomquilt 2.
Really worth seeing. Much longer, much better, now as a screensaver too.
Take the trip.
]]></description>
			<content:encoded><![CDATA[<p>Must be blogged: <a href="http://zoomquilt2.madmindworx.com/">The collaborative Zoomquilt 2</a>.<br />
Really worth seeing. Much longer, much better, now as a screensaver too.<br />
Take <a href="http://zoomquilt2.madmindworx.com/zoomquilt2.swf">the trip</a>.</p>
<img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/124031120" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/77/zoomquilt-2/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.madarco.net/77/zoomquilt-2/</feedburner:origLink></item>
		<item>
		<title>Continuations are the new threads</title>
		<link>http://feeds.feedburner.com/~r/MadarcoDevblog/~3/121316232/</link>
		<comments>http://blog.madarco.net/76/continuations-are-the-new-threads/#comments</comments>
		<pubDate>Fri, 01 Jun 2007 08:11:35 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
		
		<category><![CDATA[Flash]]></category>

		<category><![CDATA[General]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/76/continuations-are-the-new-threads/</guid>
		<description><![CDATA[I've always thought that continuations are the right answer to many if no all the network-programming problems.
What are continuations? 
A continuation represent the state of execution of a function: all the local variables and the instruction pointer (the last line executed).
(Update: At least: there can be many kind of continuations. Other than the local variables, [...]]]></description>
			<content:encoded><![CDATA[<p>I've always thought that <a href="http://en.wikipedia.org/wiki/Continuations">continuations</a> are the right answer to many if no all the network-programming problems.</p>
<h3>What are continuations? </h3>
<p>A continuation represent the state of execution of a function: all the local variables and the instruction pointer (the last line executed).<br />
(<strong>Update: At least: there can be many kind of continuations. Other than the local variables, it's possible to store the state of the entire thread/process/stack</strong>)</p>
<h3>What are them used for?</h3>
<p>You can interrupt the execution of a function and resume it later.<br />
This can be useful to create "<a href="http://en.wikipedia.org/wiki/Iterators">generators</a>": iterators made simple.</p>
<p>A generator looks like this:</p>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div class="igBar"><span id="ljavascript-9"><a href="#" onclick="javascript:showPlainTxt('javascript-9'); return false;">PLAIN TEXT</a></span></div>
<div id="javascript-9">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> next<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #66cc66;">&#40;</span>x=<span style="color: #CC0000;color:#800000;">0</span>; x &lt;arr.<span style="color: #006600;">lenght</span>; x++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;yield arr<span style="color: #66cc66;">&#91;</span>x<span style="color: #66cc66;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>The function <code>next</code> return the next element in the <code>arr</code> array every time is called. </p>
<p>When you call the function you resume the continuation, so the execution will resume from the <code>yield</code>.<br />
If you want to implement an iterator like that without generators you'll have to explicitly unroll the <code>for</code> loop.</p>
<p>The resulting code will be surely less readabe.<br />
Like:</p>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div class="igBar"><span id="ljavascript-10"><a href="#" onclick="javascript:showPlainTxt('javascript-10'); return false;">PLAIN TEXT</a></span></div>
<div id="javascript-10">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> next<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">current</span> == <span style="color: #003366; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">current</span> = <span style="color: #CC0000;color:#800000;">0</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">current</span>++;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">current</span>&gt; arr.<span style="color: #006600;">lenght</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">current</span> = <span style="color: #CC0000;color:#800000;">0</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">null</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; retrun arr<span style="color: #66cc66;">&#91;</span>x<span style="color: #66cc66;">&#93;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>This can get really worse for every non-trivial iterator (eg: tree traversal).</p>
<p>Another nice use of continuations is to generate <strong>cooperative threads</strong>.<br />
They are different from standard threads because they can't be stopped, they should cooperatively stop.</p>
<p>For example you can do:</p>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div class="igBar"><span id="lcode-11"><a href="#" onclick="javascript:showPlainTxt('code-11'); return false;">PLAIN TEXT</a></span></div>
<div id="code-11">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">function process<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; sendConnectRequest<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; yield;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; if<span style="color:#006600; font-weight:bold;">&#40;</span>!this.<span style="">connected</span><span style="color:#006600; font-weight:bold;">&#41;</span> return false;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; sendLoginRequest<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; yield;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; sendMessage<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; yield;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"msg received: "</span> + this.<span style="">response</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>The <code>process</code> function return the control to the calling function every time it has to do an asynchronous operation.<br />
Without continuations you'll have to do:</p>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div class="igBar"><span id="lcode-12"><a href="#" onclick="javascript:showPlainTxt('code-12'); return false;">PLAIN TEXT</a></span></div>
<div id="code-12">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">function process<span style="color:#006600; font-weight:bold;">&#40;</span>onComplete<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; connect<span style="color:#006600; font-weight:bold;">&#40;</span>function <span style="color:#006600; font-weight:bold;">&#40;</span>connected<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; sendLoginRequest<span style="color:#006600; font-weight:bold;">&#40;</span> function<span style="color:#006600; font-weight:bold;">&#40;</span>logged<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendMessage<span style="color:#006600; font-weight:bold;">&#40;</span> function <span style="color:#006600; font-weight:bold;">&#40;</span>response<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trace<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"msg received: "</span> + response<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onComplete<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>As you can see we have used <a href="http://en.wikipedia.org/wiki/Closure_%28computer_science%29">closures</a> in a <a href="http://en.wikipedia.org/wiki/Continuation_passing_style">Continuation Passing Style</a>:<br />
Every time you have to do an asynchronous operation, you'll have to pass a function (a callback) that will be called when the operation is done.</p>
<p>Without closures the code will look even worst, this is why recently there is a great buzz about closures in the java world.</p>
<h3>But, what have in common continuations and threads?</h3>
<p>A continuations-like style of programming (but without continuations) is possible only using threads.<br />
However, threads are the heavier and most problematic way to handle the I/O waitings. (see: <a href="http://www.kegel.com/c10k.html#top">10Kproblem</a>)<br />
You have not only to deal with concurrency problems with read/write variables, but you have to block an entire thread for every I/O operation.<br />
A better way is to use asynchronous events, like in the last two example. But of the two, which one do you prefer?</p>
<p>If your answer is like mine, take a look to:</p>
<ul>
<li><a href="http://www.mortbay.org/">Jetty servlet engine</a>, it support a limited form of one shot continuations: the function is re-executed from the beginning, what is restored is only the HTTP connection state.</li>
<li><a href="http://rifers.org/wiki/display/RIFECNT/Home">RIFE continuations</a>, it's a bytecode-level implementation in Java, these are real continuations</li>
<li><a href="http://neilmix.com/narrativejs/doc/index.html">NarrativeJS</a>, a precompiler that create a simple form of continuations in Javascript: using the <code>-></code> operator the execution can be resumed from that point.</li>
<li><strong>Update: Torsten Curdt suggest <a href="http://jakarta.apache.org/commons/sandbox/javaflow/index.html">Javaflow</a>, a continuation implementation that seems really interesting, he offers <a href="http://vafer.org/blog/tag/continuations">some tutorials on his blog too</a></strong></li>
</ul>
<p>Jetty scratched only the surface of what is possible with continuations, while with RIFE it's possible to develop highly concurrent servers using cooperative sessions instead of threads (some >10000 connections instead of 1000). See: <a href="http://mina.apache.org/">Mina Java-NIO library</a>, <a href="http://poe.perl.org/">Perl POE</a>, <a href="http://minamule.madarco.net/trac/">Mina-Mule</a>.</p>
<p>A server that uses continuations, will allow the simple and linear programming style of blocking-synchronous operations while using non-blocking ones. With a huge increment in performance.</p>
<p>In the client side, the most interesting is NarrativeJs, that use an approach that can be adapted to every language:<br />
it unroll loops and transform all local variables in object variables to generate his quasi-continuations.</p>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div class="igBar"><span id="ljavascript-13"><a href="#" onclick="javascript:showPlainTxt('javascript-13'); return false;">PLAIN TEXT</a></span></div>
<div id="javascript-13">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> boo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"start"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; sleep-&gt;<span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;color:#800000;">30</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"end"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>became:</p>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div class="igBar"><span id="ljavascript-14"><a href="#" onclick="javascript:showPlainTxt('javascript-14'); return false;">PLAIN TEXT</a></span></div>
<div id="javascript-14">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> boo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #003366; font-weight: bold;">var</span> njf1=njen<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>,arguments<span style="color: #66cc66;">&#41;</span>;nj:<span style="color: #000066; font-weight: bold;">while</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;color:#800000;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #000066; font-weight: bold;">switch</span><span style="color: #66cc66;">&#40;</span>njf1.<span style="color: #006600;">cp</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;color:#800000;">0</span>:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"start"</span><span style="color: #66cc66;">&#41;</span>;njf1.<span style="color: #006600;">pc</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;color:#800000;">1</span>,<span style="color: #003366; font-weight: bold;">null</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sleep,<span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;color:#800000;">30</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;case <span style="color: #CC0000;color:#800000;">1</span>:<span style="color: #000066; font-weight: bold;">with</span><span style="color: #66cc66;">&#40;</span>njf1<span style="color: #66cc66;">&#41;</span><span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>rv1=f.<span style="color: #006600;">apply</span><span style="color: #66cc66;">&#40;</span>c,a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>==NJSUS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span> fh;<span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"end"</span><span style="color: #66cc66;">&#41;</span>;break nj;<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>The code looks ugly but it is so to preserve line numbers.<br />
With narrativeJs you can do complex animations in a simple, linear way:</p>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div class="igBar"><span id="ljavascript-15"><a href="#" onclick="javascript:showPlainTxt('javascript-15'); return false;">PLAIN TEXT</a></span></div>
<div id="javascript-15">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">waitForClick-&gt;<span style="color: #66cc66;">&#40;</span>theButton<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">animate-&gt;<span style="color: #66cc66;">&#40;</span>theButton, <span style="color: #3366CC;">"left"</span>, <span style="color: #CC0000;color:#800000;">200</span>, <span style="color: #CC0000;color:#800000;">1000</span>, <span style="color: #CC0000;color:#800000;">20</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">theButton.<span style="color: #006600;">innerHTML</span> = <span style="color: #3366CC;">"go left"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// move the button to the left (again note the blocking operations)</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">waitForClick-&gt;<span style="color: #66cc66;">&#40;</span>theButton<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">animate-&gt;<span style="color: #66cc66;">&#40;</span>theButton, <span style="color: #3366CC;">"left"</span>, <span style="color: #CC0000;color:#800000;">0</span>, <span style="color: #CC0000;color:#800000;">1000</span>, <span style="color: #CC0000;color:#800000;">20</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>or:</p>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div class="igBar"><span id="ljavascript-16"><a href="#" onclick="javascript:showPlainTxt('javascript-16'); return false;">PLAIN TEXT</a></span></div>
<div id="javascript-16">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"myElem"</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">innerHTML</span> = fetch-&gt;<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"http://www.url.com/"</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>Really interesting now that Flash and Ajax are pushing asynchronous operations to the masses.<br />
Will we say goodbye to events, and maybe to threads as we know now?</p>
<img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/121316232" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/76/continuations-are-the-new-threads/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.madarco.net/76/continuations-are-the-new-threads/</feedburner:origLink></item>
		<item>
		<title>Simple java ftp upload and resize pics droplet &amp; applet</title>
		<link>http://feeds.feedburner.com/~r/MadarcoDevblog/~3/119860825/</link>
		<comments>http://blog.madarco.net/73/simple-java-ftp-upload-and-resize-pics-droplet-applet/#comments</comments>
		<pubDate>Sat, 26 May 2007 16:04:25 +0000</pubDate>
		<dc:creator>Madarco</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.madarco.net/73/simple-java-ftp-upload-and-resize-pics-droplet-applet/</guid>
		<description><![CDATA[Update3 (05 February 2008): now the applet doesn't upload empty folders
Update2 (04 February 2008): fixed a bug that prevented files with uppercase extension to be loaded
Update: all bug fixed, internationalized, run as as application and as an applet too
I've done a "droplet" that upload and resize pictures and folders with FTP.
Why?
Since I was looking for [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update3 (05 February 2008): now the applet doesn't upload empty folders</strong><br />
<strong>Update2 (04 February 2008): fixed a bug that prevented files with uppercase extension to be loaded</strong><br />
<strong>Update: all bug fixed, internationalized, run as as application and as an applet too</strong></p>
<p>I've done a "droplet" that upload and resize pictures and folders with FTP.</p>
<p>Why?<br />
Since I was looking for a simple and opensource "droplet" application, and I haven't found one.</p>
<p>The requisites was quite simple:</p>
<ul>
<li>upload files of some Mbs</li>
<li>resize large pictures to speed upload</li>
<li>SIMPLE: use drag&#038;drop</li>
<li>upload folders too</li>
</ul>
<p>This is the result:<br />
<img src='http://blog.madarco.net/wp-content/uploads/ftpapplet.JPG' alt='ftpApplet' /></p>
<p><strong><a href="http://blog.madarco.net/wp-content/downloads/ftpapplet/ftpApplet.jar">Download applet/droplet + sources</a></strong></p>
<p>To use it:</p>
<ol>
<li><a href="http://blog.madarco.net/wp-content/downloads/ftpapplet/ftpApplet.jar">Download the jar+html example</a></li>
<li>open sample.html</li>
<li>Drag image files and folders of pictures</li>
<li>Upload</li>
</ol>
<p>In <code>net\madarco\lightview\UploadApplet\FtpParameters.properties</code> (in the jar, use winrar to open it) you can configure the ftp parameters.  Beware that the user&#038;pass would be accessible in the .jar, so don't deploy this applet in a public area.<br />
In the next releases (if there will be) I could implement an Http upload or prompt the user for the password.</p>
<p>This applet is released as Public Domain, use it as you will. In the jar you'll find the source. Hope you'll enjoy it.</p>
<h3>Know bugs:</h3>
<p><strong><del datetime="2007-06-25T18:47:50+00:00">Can upload only once</del></strong><br />
<strong><del datetime="2007-05-31T07:35:42+00:00">Can't run as standalone application</del></strong><br />
<del datetime="2007-06-25T18:47:50+00:00"><strong>Save always as Jpg</strong> (but accept gif and bmp too :P)</del> Ok, we can live with that<br />
<del datetime="2007-06-25T18:47:50+00:00">Those bugs are easy to fix, eventually I'll do that, depending on my laziness</del> done! <img src='http://blog.madarco.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>If you are interested in how is done, continue reading:</p>
<h2>How to do a ftp droplet and applet that resizes images</h2>
<p>The best(lazy) way to achieve the upload of large files and folders is to use ftp. For this I've used org.apache.commons.net.ftp classes. They are simple and well documented.</p>
<p>To start, see the FtpUploader class.<br />
It basically iterate the files and folders specified in the swing tree component and upload them through the doUploadFile member</p>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div class="igBar"><span id="ljava-21"><a href="#" onclick="javascript:showPlainTxt('java-21'); return false;">PLAIN TEXT</a></span></div>
<div id="java-21">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">ftp</span>.<span style="color: #006600;">connect</span><span style="color: #66cc66;">&#40;</span>FtpParameters.<span style="color: #006600;">getString</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"FtpUploader.host"</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">... <span style="color: #808080; font-style: italic;">//Check if connected and authenticate</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Get all the files in the model:</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.google.com/search?q=allinurl%3ADefaultTreeModel+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">DefaultTreeModel</span></a> model = <span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3ADefaultTreeModel+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">DefaultTreeModel</span></a><span style="color: #66cc66;">&#41;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">applet</span>.<span style="color: #006600;">jPhotosTree</span>.<span style="color: #006600;">getModel</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.google.com/search?q=allinurl%3ADefaultMutableTreeNode+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">DefaultMutableTreeNode</span></a> root = <span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3ADefaultMutableTreeNode+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">DefaultMutableTreeNode</span></a><span style="color: #66cc66;">&#41;</span>model.<span style="color: #006600;">getRoot</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.google.com/search?q=allinurl%3AEnumeration+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Enumeration</span></a> nodesEnum = root.<span style="color: #006600;">children</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.google.com/search?q=allinurl%3ADefaultMutableTreeNode+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">DefaultMutableTreeNode</span></a> node;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span>nodesEnum.<span style="color: #006600;">hasMoreElements</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">doUploadFile</span><span style="color: #66cc66;">&#40;</span>file<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>doUploadFile upload files from a stream, in this way we can monitor the progress:</p>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div class="igBar"><span id="ljava-22"><a href="#" onclick="javascript:showPlainTxt('java-22'); return false;">PLAIN TEXT</a></span></div>
<div id="java-22">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.google.com/search?q=allinurl%3ABufferedInputStream+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">BufferedInputStream</span></a> imgStream = <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">resizer</span>.<span style="color: #006600;">resizeImage</span><span style="color: #66cc66;">&#40;</span>file.<span style="color: #006600;">getAbsolutePath</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">ftp</span>.<span style="color: #006600;">setFileType</span><span style="color: #66cc66;">&#40;</span>FTP.<span style="color: #006600;">IMAGE_FILE_TYPE</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.google.com/search?q=allinurl%3AOutputStream+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">OutputStream</span></a> outputStream = <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">ftp</span>.<span style="color: #006600;">storeFileStream</span><span style="color: #66cc66;">&#40;</span>file.<span style="color: #006600;">getName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">... <span style="color: #808080; font-style: italic;">//Write and monitor progress </span></div>
</li>
</ol>
</div>
</div>
</div>
<p>The resizeImage method of the JpgResizer class do what his name says:</p>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div class="igBar"><span id="ljava-23"><a href="#" onclick="javascript:showPlainTxt('java-23'); return false;">PLAIN TEXT</a></span></div>
<div id="java-23">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.google.com/search?q=allinurl%3AImage+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Image</span></a> image = <a href="http://www.google.com/search?q=allinurl%3AToolkit+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Toolkit</span></a>.<span style="color: #006600;">getDefaultToolkit</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getImage</span><span style="color: #66cc66;">&#40;</span>imageFile<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Wait for the image to load:</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.google.com/search?q=allinurl%3AMediaTracker+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">MediaTracker</span></a> mediaTracker = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3AMediaTracker+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">MediaTracker</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3AContainer+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Container</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mediaTracker.<span style="color: #006600;">addImage</span><span style="color: #66cc66;">&#40;</span>image, <span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mediaTracker.<span style="color: #006600;">waitForID</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">... <span style="color: #808080; font-style: italic;">//Calculate thumb size</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">... <span style="color: #808080; font-style: italic;">//Resize image</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">//Save as jpg:</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.google.com/search?q=allinurl%3AFile+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">File</span></a> file = <a href="http://www.google.com/search?q=allinurl%3AFile+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">File</span></a>.<span style="color: #006600;">createTempFile</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"uploadApplet"</span>, <span style="color: #ff0000;">"img"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.google.com/search?q=allinurl%3ABufferedOutputStream+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">BufferedOutputStream</span></a> out = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3ABufferedOutputStream+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">BufferedOutputStream</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?q=allinurl%3AFileOutputStream+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">FileOutputStream</span></a><span style="color: #66cc66;">&#40;</span>file<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">JPEGImageEncoder encoder = JPEGCodec.<span style="color: #006600;">createJPEGEncoder</span><span style="color: #66cc66;">&#40;</span>out<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">... <span style="color: #808080; font-style: italic;">//Set jpg quality</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">encoder.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span>thumbImage<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">out.<span style="color: #006600;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3ABufferedInputStream+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">BufferedInputStream</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3AFileInputStream+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">FileInputStream</span></a><span style="color: #66cc66;">&#40;</span>file<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>For the drag&#038;drop code see DropFilesHandler class, in the <code>drop</code> method you can find the code that get the file name dropped.</p>
<p>Simple, isn't it?</p>
<p>To run it as an applet, you'll have to sign it. <a href="http://mindprod.com/jgloss/keytoolexe.html">This is a good guide</a>.<br />
In short:</p>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div class="igBar"><span id="lcode-24"><a href="#" onclick="javascript:showPlainTxt('code-24'); return false;">PLAIN TEXT</a></span></div>
<div id="code-24">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">keytool.<span style="">exe</span> -genkey -storepass %jarsignerpassword -keyalg DSA -alias madarcoftpapplet -dname <span style="color:#CC0000;">"CN=madarco.net, OU=Java Code, O=Madarco, L=Italy, ST=Italy, C=IT, MAILADDRESS=ftpapplet@madarco.it DC=ftpapplet, DC=com"</span> -validity <span style="color:#800000;color:#800000;">999</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">keytool.<span style="">exe</span> -export&nbsp; -storepass %madapass -alias madarcoftpapplet -rfc -file ftpapplet.<span style="">cer</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">jarsigner ftpApplet.<span style="">jar</span> madarcoftpapplet </div>
</li>
</ol>
</div>
</div>
</div>
<p>The code is really quick&#038;dirty, however, even if there are many things that can be improved, this can be used as a base to implement your own droplet.</p>
<img src="http://feeds.feedburner.com/~r/MadarcoDevblog/~4/119860825" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.madarco.net/73/simple-java-ftp-upload-and-resize-pics-droplet-applet/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.madarco.net/73/simple-java-ftp-upload-and-resize-pics-droplet-applet/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic Page Served (once) in 2.346 seconds --><!-- Cached page served by WP-Cache -->
