<?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; c#</title>
	<atom:link href="http://penguinsoft.us/tag/c/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>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>

