<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>coding 360°</title>
	<atom:link href="http://coding360.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://coding360.wordpress.com</link>
	<description>code around</description>
	<lastBuildDate>Thu, 22 Jan 2009 08:55:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='coding360.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>coding 360°</title>
		<link>http://coding360.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://coding360.wordpress.com/osd.xml" title="coding 360°" />
	<atom:link rel='hub' href='http://coding360.wordpress.com/?pushpress=hub'/>
		<item>
		<title>#3. Encrypted the whole class with javax.crypto</title>
		<link>http://coding360.wordpress.com/2009/01/22/3-encrypted-the-whole-class-with-javaxcrypto/</link>
		<comments>http://coding360.wordpress.com/2009/01/22/3-encrypted-the-whole-class-with-javaxcrypto/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 08:55:07 +0000</pubDate>
		<dc:creator>mahn</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://coding360.wordpress.com/2009/01/22/3-encrypted-the-whole-class-with-javaxcrypto/</guid>
		<description><![CDATA[Many may have been googled around with this very topic and have came across with many example; but most of them haven’t depicted the practical one. So, here I tried to conduct practical one. Hope this will help We’ll started with how to generated the SecretKey without creating a new one every time you have [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=coding360.wordpress.com&amp;blog=5436476&amp;post=10&amp;subd=coding360&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Many may have been googled around with this very topic and have came across with many example; but most of them haven’t depicted the practical one.</p>
<p>So, here I tried to conduct practical one. Hope this will help <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>We’ll started with how to generated the SecretKey without creating a new one every time you have run the software (no more random).I’ll illustrate this example with the “DES” algorithm. The “DES” algorithm required at least 8 bytes key. Here is SecretKey generator function.</p>
<div style="border-bottom:gray 1px solid;border-left:gray 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:consolas, &#39;max-height:200px;font-size:8pt;overflow:auto;border-top:gray 1px solid;cursor:text;border-right:gray 1px solid;margin:20px 0 10px;padding:4px;">
<div style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;">
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> SecretKey generateKey(String pass) </pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>     throws InvalidKeyException </pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span> {</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>         SecretKey key = <span style="color:#0000ff;">null</span>;</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>         </pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>         DESKeySpec ks = <span style="color:#0000ff;">new</span> DESKeySpec( pass.getBytes() );    <span style="color:#008000;">// required 8 bytes at least</span></pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>         SecretKeyFactory factory;</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>         <span style="color:#0000ff;">try</span> {</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>             factory = SecretKeyFactory.getInstance( <span style="color:#006080;">&quot;DES&quot;</span> );</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>             key = factory.generateSecret( ks );</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>         } <span style="color:#0000ff;">catch</span> (NoSuchAlgorithmException e) {</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>             e.printStackTrace();</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>         } <span style="color:#0000ff;">catch</span> (InvalidKeySpecException e) {</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>             e.printStackTrace();</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>         }</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>         <span style="color:#0000ff;">return</span> key;</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span>     }</pre>
</p></div>
</div>
<p>After you have a function for generated the key; Let’s translate your class to array of byte and vice versa.</p>
<div style="border-bottom:gray 1px solid;border-left:gray 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:consolas, &#39;max-height:200px;font-size:8pt;overflow:auto;border-top:gray 1px solid;cursor:text;border-right:gray 1px solid;margin:20px 0 10px;padding:4px;">
<div style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;">
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">byte</span>[] createByteArrayFromObject(Serializable o) throws IOException {</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>     ByteArrayOutputStream baos = <span style="color:#0000ff;">new</span> ByteArrayOutputStream();</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     ObjectOutputStream oos;</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     oos = <span style="color:#0000ff;">new</span> ObjectOutputStream(baos);</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>     oos.writeObject(o);</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>     oos.close();</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>     <span style="color:#0000ff;">return</span> baos.toByteArray();</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span> }</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>&#160; </pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> Object createObjectFromByteArray(<span style="color:#0000ff;">byte</span>[] byteObject) throws IOException, ClassNotFoundException {</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>     ByteArrayInputStream bais;</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>     ObjectInputStream ois;</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>     bais = <span style="color:#0000ff;">new</span> ByteArrayInputStream(byteObject);</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>     ois = <span style="color:#0000ff;">new</span> ObjectInputStream(bais);</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>     <span style="color:#0000ff;">return</span> ois.readObject();</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>     </pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span> }</pre>
</p></div>
</div>
<p>This is how to encrypt the class; supply the class’s array of byte through bytes parameter.</p>
<div style="border-bottom:gray 1px solid;border-left:gray 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:consolas, &#39;max-height:200px;font-size:8pt;overflow:auto;border-top:gray 1px solid;cursor:text;border-right:gray 1px solid;margin:20px 0 10px;padding:4px;">
<div style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;">
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> String encryptBytes(SecretKey key, <span style="color:#0000ff;">byte</span>[] bytes) {</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>     <span style="color:#0000ff;">try</span> {</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>         Cipher ecipher = Cipher.getInstance(<span style="color:#006080;">&quot;DES&quot;</span>);</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>         ecipher.init(Cipher.ENCRYPT_MODE, key);</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>&#160; </pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>         <span style="color:#008000;">// re-adjust the bytes accordingly to the protocol</span></pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>         <span style="color:#0000ff;">byte</span>[] arranged = bytes;</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>         </pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>         <span style="color:#008000;">// Encrypt</span></pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>         <span style="color:#0000ff;">byte</span>[] enc = ecipher.doFinal(arranged);</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>&#160; </pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>         <span style="color:#008000;">// Encode bytes to base64 to get a string</span></pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>         <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">new</span> sun.misc.BASE64Encoder().encode(enc);</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>     } <span style="color:#0000ff;">catch</span> (javax.crypto.BadPaddingException e) {</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>     } <span style="color:#0000ff;">catch</span> (IllegalBlockSizeException e) {</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>     } <span style="color:#0000ff;">catch</span> (javax.crypto.NoSuchPaddingException e) {</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span>     } <span style="color:#0000ff;">catch</span> (java.security.NoSuchAlgorithmException e) {</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  18:</span>     } <span style="color:#0000ff;">catch</span> (java.security.InvalidKeyException e) {</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  19:</span>     }</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  20:</span>     <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">null</span>;</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  21:</span> }</pre>
</p></div>
</div>
<div class="csharpcode-wrapper">
<div class="csharpcode">
<div class="csharpcode-wrapper">
<div class="csharpcode">Now to decrypt:</div>
<div style="border-bottom:gray 1px solid;border-left:gray 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:consolas, &#39;max-height:200px;font-size:8pt;overflow:auto;border-top:gray 1px solid;cursor:text;border-right:gray 1px solid;margin:20px 0 10px;padding:4px;">
<div style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;">
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">byte</span>[] decryptBytes(String str) {</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>     <span style="color:#0000ff;">try</span> {</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>         Cipher dcipher;</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>&#160; </pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>         dcipher = Cipher.getInstance(<span style="color:#006080;">&quot;DES&quot;</span>);</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>         dcipher.init(Cipher.DECRYPT_MODE, key);</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>&#160; </pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>         <span style="color:#008000;">// Decode base64 to get bytes</span></pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>         <span style="color:#0000ff;">byte</span>[] dec = <span style="color:#0000ff;">new</span> sun.misc.BASE64Decoder().decodeBuffer(str);</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>&#160; </pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>         <span style="color:#008000;">// Decrypt</span></pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>         <span style="color:#0000ff;">byte</span>[] unarranged = dcipher.doFinal(dec);</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>         <span style="color:#008000;">// re-adjust the bytes accordingly to the protocol</span></pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>         <span style="color:#0000ff;">byte</span>[] arranged = unarranged;</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>         </pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>         <span style="color:#0000ff;">return</span> arranged;</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span>     } <span style="color:#0000ff;">catch</span> (javax.crypto.BadPaddingException e) {</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  18:</span>     } <span style="color:#0000ff;">catch</span> (IllegalBlockSizeException e) {</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  19:</span>     } <span style="color:#0000ff;">catch</span> (UnsupportedEncodingException e) {</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  20:</span>     } <span style="color:#0000ff;">catch</span> (java.io.IOException e) {</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  21:</span>     } <span style="color:#0000ff;">catch</span> (javax.crypto.NoSuchPaddingException e) {</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  22:</span>     } <span style="color:#0000ff;">catch</span> (java.security.NoSuchAlgorithmException e) {</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  23:</span>     } <span style="color:#0000ff;">catch</span> (java.security.InvalidKeyException e) {</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  24:</span>     }</pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  25:</span>     <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">null</span>;</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  26:</span> }</pre>
</p></div>
</p></div>
<div class="csharpcode">&#160;</div>
<div class="csharpcode">Now encrypted this class’s array of byte with the key generated by the first function.</div>
<div class="csharpcode">&#160;</div>
<div class="csharpcode">encrypt:</div>
<div class="csharpcode">&#160;</div>
<div style="border-bottom:gray 1px solid;border-left:gray 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:consolas, &#39;max-height:200px;font-size:8pt;overflow:auto;border-top:gray 1px solid;cursor:text;border-right:gray 1px solid;margin:20px 0 10px;padding:4px;">
<div style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;">
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> String password = <span style="color:#006080;">&quot;this is the password string used as key to encrypt&quot;</span>;</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>&#160; </pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span> SecretKey key = generateKey(password);</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>&#160; </pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span> ObjectToEncrypt ote = <span style="color:#0000ff;">new</span> ObjectToEncrypt();</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span> String encryptedString = encryptBytes(key, createByteArrayFromObject(ote)); </pre>
</p></div>
</p></div>
<div class="csharpcode">&#160;</div>
<div class="csharpcode">decrypt:</div>
</p></div>
</p></div>
</div>
<div style="border-bottom:gray 1px solid;border-left:gray 1px solid;line-height:12pt;background-color:#f4f4f4;width:97.5%;font-family:consolas, &#39;max-height:200px;font-size:8pt;overflow:auto;border-top:gray 1px solid;cursor:text;border-right:gray 1px solid;margin:20px 0 10px;padding:4px;">
<div style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;padding:0;">
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> String password = <span style="color:#006080;">&quot;the same password that used earlier&quot;</span>;</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>&#160; </pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span> String encryptedString = <span style="color:#006080;">&quot;....&quot;</span>; <span style="color:#008000;">// this is encrypted string</span></pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>&#160; </pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span> SecretKey key = generateKey(password);</pre>
<pre style="line-height:12pt;background-color:#f4f4f4;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>&#160; </pre>
<pre style="line-height:12pt;background-color:white;width:100%;font-family:consolas, &#39;color:black;font-size:8pt;overflow:visible;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span> ObjectToEncrypt ote = (ObjectToEncrypt) createObjectFromByteArray(decryptBytes(key, encryptedString));</pre>
</p></div>
</div>
<p>Note that the object to encrypted/decrypted must implements Serializable.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/coding360.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/coding360.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/coding360.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/coding360.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/coding360.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/coding360.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/coding360.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/coding360.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/coding360.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/coding360.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/coding360.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/coding360.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/coding360.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/coding360.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=coding360.wordpress.com&amp;blog=5436476&amp;post=10&amp;subd=coding360&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://coding360.wordpress.com/2009/01/22/3-encrypted-the-whole-class-with-javaxcrypto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/70ee224d37c8745f1f37334c49684767?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mahn</media:title>
		</media:content>
	</item>
		<item>
		<title>#2. Create a thread with class’s method.</title>
		<link>http://coding360.wordpress.com/2009/01/14/2-create-a-thread-with-classs-method/</link>
		<comments>http://coding360.wordpress.com/2009/01/14/2-create-a-thread-with-classs-method/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 12:05:52 +0000</pubDate>
		<dc:creator>mahn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://coding360.wordpress.com/2009/01/14/2-create-a-thread-with-classs-method/</guid>
		<description><![CDATA[In C/C++ starting the thread requires a static function as a starting address. Thus, in case that you want to invoke the thread with the target class’s method is a little bit complicated. Here is a way that you can make it happen First of, we got a very simple class name CSample and you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=coding360.wordpress.com&amp;blog=5436476&amp;post=5&amp;subd=coding360&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In C/C++ starting the thread requires a static function as a starting address. Thus, in case that you want to invoke the thread with the target class’s method is a little bit complicated.</p>
<p>Here is a way that you can make it happen <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>First of, we got a very simple class name <strong>CSample</strong> and you want to create a thread with your own class method in order to let your thread has an access to your class memory space. In this example let’s say that function is named as <strong>targetFunctionToCall()</strong></p>
<p>Now to create thread with this function simply you are required to have a static method to invoke this function first. I’ll name it with <strong>s_</strong> prefix which stands for <strong>static</strong>.</p>
<p>In the implementation part we will create the thread with the static function <strong>s_targetFunctionToCall. </strong>And in this function it’ll invoke your <strong>targetFunctionToCall</strong> again. Here is what your header files would look like.</p>
<p>csample.h</p>
<div style="font-size:8pt;overflow:auto;width:97.5%;cursor:text;max-height:200px;line-height:12pt;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">class</span> CSample</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   2:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   3:</span> <span style="color:#0000ff;">public</span>:</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   4:</span>     CSample();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   5:</span>     <span style="color:#0000ff;">virtual</span> ~CSample();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   6:</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   7:</span>     <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> s_targetFunctionToCall(<span style="color:#0000ff;">void</span> *);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   8:</span>     <span style="color:#0000ff;">void</span> targetFunctionToCall();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   9:</span> };</pre>
<p> </p></div>
</div>
<p>csample.cpp</p>
<div style="font-size:8pt;overflow:auto;width:97.5%;cursor:text;max-height:200px;line-height:12pt;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   1:</span> #include <span style="color:#006080;">"csample.h"</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   2:</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   3:</span> CSample::CSample()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   4:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   5:</span>     ::CreateThread(NULL, 0, (unsigned long (__stdcall *) (void *)) s_targetFunctionToCall, (<span style="color:#0000ff;">void</span> *) <span style="color:#0000ff;">this</span>, 0, NULL);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   6:</span> }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   7:</span> CSample::~CSample()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   8:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">   9:</span> }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  10:</span> <span style="color:#0000ff;">void</span> CSample::s_targetFunctionToCall(<span style="color:#0000ff;">void</span> * instance)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  11:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  12:</span>     ((CSample *) instance)-&gt;targetFunctionToCall();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  13:</span>     ::ExitThread(0);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  14:</span> }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  15:</span> <span style="color:#0000ff;">void</span> CSample::targetFunctionToCall()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  16:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  17:</span>     <span style="color:#008000;">// do your things</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#606060;">  18:</span> }</pre>
<p> </p></div>
</div>
<p>As you can see the <strong>s_targetFunctionToCall</strong> redirect the code flow back to the old class by the <em>instance</em> parameter.</p>
<p>You can also modify your arguments since void * can pass anything to it, you may modify it with expansion with struct that packed everything you need inside and then pass it through.</p>
<p>Hope this will help <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/coding360.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/coding360.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/coding360.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/coding360.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/coding360.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/coding360.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/coding360.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/coding360.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/coding360.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/coding360.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/coding360.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/coding360.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/coding360.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/coding360.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=coding360.wordpress.com&amp;blog=5436476&amp;post=5&amp;subd=coding360&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://coding360.wordpress.com/2009/01/14/2-create-a-thread-with-classs-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/70ee224d37c8745f1f37334c49684767?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mahn</media:title>
		</media:content>
	</item>
		<item>
		<title>#1. Red5&#8217;s &#8220;Hello, World.&#8221;</title>
		<link>http://coding360.wordpress.com/2008/11/07/1-red5s-hello-world/</link>
		<comments>http://coding360.wordpress.com/2008/11/07/1-red5s-hello-world/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 10:52:14 +0000</pubDate>
		<dc:creator>mahn</dc:creator>
				<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Red5]]></category>

		<guid isPermaLink="false">http://coding360.wordpress.com/2008/11/07/1-red5s-hello-world/</guid>
		<description><![CDATA[Intro. As the very first entry of my very first blog . Let me describe about what I’m gonna talking about. The Red5, is an open-source data service for flex technology. Many that has been working around the flex should have known this software for quite sometime. But for those who don’t; Flex data service, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=coding360.wordpress.com&amp;blog=5436476&amp;post=4&amp;subd=coding360&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Intro.</h2>
<p>As the very first entry of my very first blog <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . Let me describe about what I’m gonna talking about. The <em>Red5</em>, is an open-source data service for flex technology. Many that has been working around the flex should have known this software for quite sometime. But for those who don’t; Flex data service, or from my understanding, it’s a server side of the software. It’s can provided many various kind of service. The <em>Red5 </em>act upon the basis of connection providing between client-server and from that point it’s also provided the client-client.</p>
<p>Now, that’s too much for the brief you can certainly find out more information from their <a href="http://osflash.org/red5" target="_blank"><em>Red5</em> official site</a>. So, finally, here is the main idea of this entry: “How to use this Red5?”.</p>
<p>Here are some basic example of our well known “Hello, World”.</p>
<p>Let’s start with server side first. </p>
<ol>
<li>download the red5 from their <a href="http://red5.googlecode.com/svn/java/server/trunk/" target="_blank">svn link address</a>. </li>
<li>open your eclipse, import the project. </li>
<li>create a new folder in <strong>webapps/[your project’s name]/WEB-INF/src</strong>. And link that as a source folder. </li>
<li>in your project folder, with sub directory “WEB-INF” make sure it contains these files (these files can be copies from the template directory located in <strong>doc/templates/myapp/WEB-INF</strong>).
<ol>
<li>red5-web.properties </li>
<li>red5-web.xml </li>
<li>web.xml </li>
</ol>
</li>
<li>leave these 3 files as it be first. We’ll come back to it later. </li>
<li>Now let’s start coding!. </li>
</ol>
<h2>Server Side: Java.</h2>
<blockquote><p><font color="#333333">From my pov; I rather prefer jdk1.6 instead of 1.5.</font></p>
</blockquote>
<p>To create a new application for Red5 server, that allows an access from client side. You can easily extends the <strong>ApplicationAdapter </strong>class of Red5.</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, &#39;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Application extends ApplicationAdapter {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> final Log log = LogFactory.getLog( Application.<span style="color:#0000ff;">class</span> );</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>     <span style="color:#cc6633;">@Override</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>     <span style="color:#0000ff;">public</span> boolean appStart(IScope scope)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>         <span style="color:#008000;">// initialize application.</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>         log.info(<span style="color:#006080;">&quot;Application.appStart()&quot;</span>);        </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>         <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">true</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>     <span style="color:#cc6633;">@Override</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>     <span style="color:#0000ff;">public</span> boolean appConnect( IConnection conn , Object[] <span style="color:#0000ff;">params</span> )</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>         log.info(<span style="color:#006080;">&quot;Application.appConnect()&quot;</span>);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span>         <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">true</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  18:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  19:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  20:</span>     <span style="color:#cc6633;">@Override</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  21:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> appDisconnect( IConnection conn )</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  22:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  23:</span>         log.info( <span style="color:#006080;">&quot;Application.appDisconnect()&quot;</span>);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  24:</span>         super.appDisconnect( conn );</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  25:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  26:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  27:</span>     <span style="color:#cc6633;">@Override</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  28:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> appStop( IScope app )</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  29:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  30:</span>         log.info( <span style="color:#006080;">&quot;Application.appStop()&quot;</span>);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  31:</span>         super.appStop( app );</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  32:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  33:</span> }</pre>
</p></div>
</div>
<p>this is a very basic code. Which do exactly nothing, just allow the client connect to the server. Now let’s add some method for the client to call from their side.</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, &#39;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">public</span> String hello(String words) {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>     <span style="color:#0000ff;">return</span> <span style="color:#006080;">&quot;Hello &quot;</span> + words;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span> }</pre>
</p></div>
</div>
<p>the code above is a function that allow the calls from the client which contains one argument, and reply back with the “Hello “ concats to it’s head, and this will be called from client.</p>
<p>That’s much for the server’s code for now.</p>
<h2>Server Side: Configure xml files.</h2>
<p>Now to enable the <em>Red5</em> to knows your application, we need to configures the xml file that we left earlier.</p>
<h3></h3>
<ul>
<li><strong>red5-web.properties</strong> </li>
<ul>
<ul>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, &#39;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> webapp.contextPath=/[your project folder name] </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> webapp.virtualHosts=localhost,127.0.0.1 </pre>
</p></div>
</p></div>
</ul>
</ul>
<li><strong>red5-web.xml</strong> </li>
<ul>
<li>in this file it’s defined the class path that reference to the certain class that will be executed on the client’s requests. Locate the bean with id of <strong>“web.handler”</strong> and supply your class path to your <strong>Application</strong> class.</li>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, &#39;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#008000;">&lt;!-- Customized software spring injection --&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">bean</span> <span style="color:#ff0000;">id</span><span style="color:#0000ff;">=&quot;web.handler&quot;</span> </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     <span style="color:#ff0000;">class</span><span style="color:#0000ff;">=&quot;class.path.to.your.Application&quot;</span><span style="color:#0000ff;">/&gt;</span></pre>
</p></div>
</p></div>
</ul>
<li><strong>web.xml</strong></li>
<ul>
<li>this file state the lookup path for your application. Configure the parameter by name <strong>webAppRootKey </strong>will be suffice.</li>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, &#39;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">context-param</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>     <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">param-name</span><span style="color:#0000ff;">&gt;</span>webAppRootKey<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">param-name</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">param-value</span><span style="color:#0000ff;">&gt;</span>/[your project's name]<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">param-value</span><span style="color:#0000ff;">&gt;</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span> <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">context-param</span><span style="color:#0000ff;">&gt;</span></pre>
</p></div>
</p></div>
</ul>
</ul>
<p>that’s much for the configuration you will touch these files again only when you need to add services in your application.</p>
<h2>Client Side: Flex.</h2>
</p>
</p>
<p>For flex, create a new actionscript class, To calls the server side. you only need a <strong>NetConnection</strong> class to made the call to your server. Here is the code sample.</p>
<div style="border-right:gray 1px solid;border-top:gray 1px solid;font-size:8pt;overflow:auto;border-left:gray 1px solid;width:97.5%;cursor:text;max-height:200px;line-height:12pt;border-bottom:gray 1px solid;font-family:consolas, &#39;background-color:#f4f4f4;margin:20px 0 10px;padding:4px;">
<div style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> package com.sylli.mce.flex.client</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     import flash.events.NetStatusEvent;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     import flash.net.NetConnection;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>     import flash.net.ObjectEncoding;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>     import flash.net.Responder;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>     </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Red5Facade</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">var</span> m_nc:NetConnection;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">var</span> m_rs:Responder;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>         <span style="color:#008000;">/* constructor */</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">function</span> Red5Facade( )</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>         {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>             trace(<span style="color:#006080;">&quot;Establish connection. &quot;</span>);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  18:</span>             <span style="color:#008000;">// create responder for string return-type.</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  19:</span>             m_rs = <span style="color:#0000ff;">new</span> Responder(debugStringResponderFunction, <span style="color:#0000ff;">null</span>);            </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  20:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  21:</span>             m_nc = <span style="color:#0000ff;">new</span> NetConnection( );    <span style="color:#008000;">// new netconnection</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  22:</span>             m_nc.objectEncoding = ObjectEncoding.AMF0;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  23:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  24:</span>             <span style="color:#008000;">// netstatus event listening</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  25:</span>             m_nc.addEventListener( NetStatusEvent.NET_STATUS , netStatus );</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  26:</span>             </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  27:</span>             <span style="color:#008000;">// connect to red5, passing false as parameter</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  28:</span>             m_nc.connect( <span style="color:#006080;">&quot;rtmp://localhost/[your project's name]&quot;</span> );</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  29:</span>         }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  30:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  31:</span>         <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">function</span> netStatus ( <span style="color:#0000ff;">event</span>:NetStatusEvent ):<span style="color:#0000ff;">void</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  32:</span>         {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  33:</span>             trace( <span style="color:#006080;">&quot;NetStatus: &quot;</span> + <span style="color:#0000ff;">event</span>.info.code );</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  34:</span>             <span style="color:#0000ff;">if</span> ( <span style="color:#0000ff;">event</span>.info.code == <span style="color:#006080;">&quot;NetConnection.Connect.Rejected&quot;</span> )</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  35:</span>             {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  36:</span>                 <span style="color:#008000;">// trace reject message</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  37:</span>                 trace( <span style="color:#0000ff;">event</span>.info.application );</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  38:</span>             }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  39:</span>         }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  40:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  41:</span>         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">function</span> helloWorld ( words:String ):<span style="color:#0000ff;">void</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  42:</span>         {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  43:</span>             m_nc.call(<span style="color:#006080;">&quot;hello&quot;</span>, m_rs, words); </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  44:</span>         }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  45:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  46:</span>         <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">function</span> debugStringResponderFunction(_val:String):<span style="color:#0000ff;">void</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  47:</span>         {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  48:</span>             trace(<span style="color:#006080;">&quot;String returns &quot;</span> + _val);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  49:</span>         }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:#f4f4f4;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  50:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;font-family:consolas, &#39;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  51:</span> }</pre>
</p></div>
</div>
<p>Finally, the test drive, with your eclipse start the Red5 server by create new run, using <strong>org.red5.server.Standalone</strong> which will starts all the server nodes existing in their <strong>webapps</strong> directory.</p>
<p>Then start debug your flex application, try call your class methods. if it made a proper connection to the red5’s. (start as a debug mode, so the trace() function would print properly.</p>
<p>&#160;</p>
<p>Hope this will help. Any comments will be appreciated.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/coding360.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/coding360.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/coding360.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/coding360.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/coding360.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/coding360.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/coding360.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/coding360.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/coding360.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/coding360.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/coding360.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/coding360.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/coding360.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/coding360.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=coding360.wordpress.com&amp;blog=5436476&amp;post=4&amp;subd=coding360&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://coding360.wordpress.com/2008/11/07/1-red5s-hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/70ee224d37c8745f1f37334c49684767?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mahn</media:title>
		</media:content>
	</item>
	</channel>
</rss>
