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

<channel>
	<title>Penguinsoft &#187; flash</title>
	<atom:link href="http://penguinsoft.us/tag/flash/feed/" rel="self" type="application/rss+xml" />
	<link>http://penguinsoft.us</link>
	<description>Application Development, Web Development, Innovative Software Solutions</description>
	<lastBuildDate>Mon, 23 Jan 2012 18:45:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Sanitizing Input in Flash</title>
		<link>http://penguinsoft.us/2010/06/sanitizing-input-in-flash/</link>
		<comments>http://penguinsoft.us/2010/06/sanitizing-input-in-flash/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 00:17:38 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[Code and Servers]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[bbs]]></category>
		<category><![CDATA[characters]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[sanitizing]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://penguinsoft.us/?p=252</guid>
		<description><![CDATA[Let&#8217;s say for example you are creating a bulletin board system or some post system from within flash and you would like to restrict the use of any html or special characters. It turns out there is a very simple and elegant way you can strip out or replace any characters you want to. First ...]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say for example you are creating a bulletin board system or some post system from within flash and you would like to restrict the use of any html or special characters. <span id="more-252"></span>It turns out there is a very simple and elegant way you can strip out or replace any characters you want to.</p>
<p>First we want to declare an array in as3 with all the characters that we don&#8217;t want in our string.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> htmlChars:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
htmlChars<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
htmlChars<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
htmlChars<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;&amp;gt;&quot;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
htmlChars<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;&amp;lt;&quot;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;&quot;</span>;</pre></div></div>

<p>Then all we have to do is to create our function that takes a string as an argument and returns our safe sanitized string.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> sanitizeInput<span style="color: #66cc66;">&#40;</span>msg:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> htmlChar:<span style="color: #0066CC;">Object</span> <span style="color: #b1b100;">in</span> htmlChars<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
    	     msg = msg.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span>htmlChar<span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">join</span><span style="color: #66cc66;">&#40;</span>htmlChars<span style="color: #66cc66;">&#91;</span>htmlChar<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> msg;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now we can call our function.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> safeString:<span style="color: #0066CC;">String</span> = sanitizeInput<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;</span></pre></div></div>

<p>What we can also do is to replace characters in the string. For example&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">htmlChars<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Bye&quot;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;CYA&quot;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> safeString:<span style="color: #0066CC;">String</span> = sanitizeInput<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Bye for now<span style="color: #000099; font-weight: bold;">\&quot;</span>);
// safeString = &quot;</span>CYA <span style="color: #b1b100;">for</span> now<span style="color: #ff0000;">&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://penguinsoft.us/2010/06/sanitizing-input-in-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Socket Policy Server</title>
		<link>http://penguinsoft.us/2010/03/flash-socket-policy-server/</link>
		<comments>http://penguinsoft.us/2010/03/flash-socket-policy-server/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 17:54:19 +0000</pubDate>
		<dc:creator>Kenneth</dc:creator>
				<category><![CDATA[Code and Servers]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[policy file]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[socket]]></category>
		<category><![CDATA[tcp]]></category>
		<category><![CDATA[tcplistener]]></category>

		<guid isPermaLink="false">http://penguinsoft.us/?p=208</guid>
		<description><![CDATA[We have a custom built communication server that can handle video/audio and text. Well a while back we wrote a flash client for this server. Well Adobe had just updated their flash player to include some new security enhancements one of which involved not allowing cross domain policy files to be served up via HTTP. ...]]></description>
			<content:encoded><![CDATA[<p>We have a custom built communication server that can handle video/audio and text. Well a while back we wrote a flash client for this server. Well Adobe had just updated their flash player to include some new security enhancements one of which involved not allowing cross domain policy files to be served up via HTTP. There had to be a server listening on port 843 in order to serve the policy file. So I went to task of whipping one up real fast.<span id="more-208"></span></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> TcpListener tcl<span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">//Generate policy</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> response <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">+</span>
                                    <span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\0</span>&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Starting up server...&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            tcl <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TcpListener<span style="color: #008000;">&#40;</span>IPAddress<span style="color: #008000;">.</span><span style="color: #0000FF;">Any</span>, <span style="color: #FF0000;">843</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            tcl<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            tcl<span style="color: #008000;">.</span><span style="color: #0000FF;">BeginAcceptSocket</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> AsyncCallback<span style="color: #008000;">&#40;</span>AcceptCallback<span style="color: #008000;">&#41;</span>, tcl<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Hit enter/return to close&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadLine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> AcceptCallback<span style="color: #008000;">&#40;</span>IAsyncResult ar<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">try</span>
            <span style="color: #008000;">&#123;</span>
                TcpListener listener <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
                Socket client <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
&nbsp;
                listener <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>TcpListener<span style="color: #008000;">&#41;</span>ar<span style="color: #008000;">.</span><span style="color: #0000FF;">AsyncState</span><span style="color: #008000;">;</span>
                client <span style="color: #008000;">=</span> listener<span style="color: #008000;">.</span><span style="color: #0000FF;">EndAcceptSocket</span><span style="color: #008000;">&#40;</span>ar<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                NetworkStream ns <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NetworkStream<span style="color: #008000;">&#40;</span>client<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                StreamReader sr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StreamReader<span style="color: #008000;">&#40;</span>ns<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                StreamWriter sw <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StreamWriter<span style="color: #008000;">&#40;</span>ns<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                sr<span style="color: #008000;">.</span><span style="color: #0000FF;">Read</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008080; font-style: italic;">//Send policy</span>
                sw<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span>response<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                sw<span style="color: #008000;">.</span><span style="color: #0000FF;">Flush</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                ns<span style="color: #008000;">.</span><span style="color: #0000FF;">Flush</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008080; font-style: italic;">//Cleanup</span>
                sw<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                sr<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                ns<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                client<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008080; font-style: italic;">//Do it again!</span>
                tcl<span style="color: #008000;">.</span><span style="color: #0000FF;">BeginAcceptSocket</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> AsyncCallback<span style="color: #008000;">&#40;</span>AcceptCallback<span style="color: #008000;">&#41;</span>, tcl<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception e<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>e<span style="color: #008000;">.</span><span style="color: #0000FF;">Message</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

<p>So there it is. A quick and dirty flash socket policy server written in c#. You can compile/run this in windows or linux running mono. I&#8217;ve been using a modified version of this for quite some time to handle tens of thousands of users and never had a problem with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://penguinsoft.us/2010/03/flash-socket-policy-server/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

