| <!DOCTYPE html> |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| <head> |
| <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> |
| <meta content="en-us" http-equiv="Content-Language" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| |
| <link href="/static/images/favicon.ico" rel="shortcut icon" /> |
| <link href="/static/css/style.css" rel="stylesheet" type="text/css" /> |
| <link href="/static/css/codehilite.css" rel="stylesheet" type="text/css" /> |
| <link href="/static/css/bootstrap.css" media="screen, projection" rel="stylesheet" type="text/css" /> |
| <link href="/static/css/thrift.css" media="screen, projection" rel="stylesheet" type="text/css" /> |
| |
| <script src="/static/js/jquery.min.js"></script> |
| <script src="/static/js/bootstrap-dropdown.js"></script> |
| <script src="/static/js/bootstrap-tab.js"></script> |
| <script src="/static/js/thrift.js"></script> |
| |
| <title>Apache Thrift - Actionscript 3.0</title> |
| </head> |
| <body> |
| <div class="navbar"> |
| <div class="navbar-inner"> |
| <div class="container"> |
| <a class="brand" href="/">Apache Thrift ™</a> |
| <div class="nav-collapse"> |
| <ul class="nav pull-right"> |
| <li><a href="/download">Download</a></li> |
| <li><a href="/docs">Documentation</a></li> |
| <li><a href="/developers">Developers</a></li> |
| <li><a href="/lib">Libraries</a></li> |
| <li><a href="/tutorial">Tutorial</a></li> |
| <li><a href="/test">Test Suite</a></li> |
| <li><a href="/about">About</a></li> |
| <li class="dropdown"> |
| <a href="#" class="dropdown-toggle" data-toggle="dropdown">Apache <b class="caret"></b></a> |
| <ul class="dropdown-menu"> |
| <li><a href="http://www.apache.org/" target="_blank">Apache Home</a></li> |
| <li><a href="http://www.apache.org/licenses/" target="_blank">Apache License v2.0</a></li> |
| <li><a href="http://www.apache.org/foundation/sponsorship.html" target="_blank">Donate</a></li> |
| <li><a href="http://www.apache.org/foundation/thanks.html" target="_blank">Thanks</a></li> |
| <li><a href="http://www.apache.org/security/" target="_blank">Security</a></li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| </div> |
| </div> |
| </div> |
| |
| <div class="container"> |
| <h2>Actionscript 3.0 Tutorial</h2> |
| |
| <h3>Introduction</h3> |
| |
| <p> |
| All Apache Thrift tutorials require that you have: |
| |
| <ol> |
| <li>The Apache Thrift Compiler and Libraries, see <a href="/download">Download</a> and <a href="/docs/BuildingFromSource">Building from Source</a> for more details.</li> |
| <li>Generated the <a href="https://github.com/apache/thrift/blob/master/tutorial/tutorial.thrift">tutorial.thrift</a> and <a href="https://github.com/apache/thrift/blob/master/tutorial/shared.thrift">shared.thrift</a> files:<br> |
| <pre><code>thrift -r --gen as3 tutorial.thrift</code></pre> |
| </li> |
| <li>Followed all prerequisites listed below.</li> |
| </ol> |
| |
| <h3 id="prerequisites">Prerequisites</h3> |
| |
| <h3 id="client">Client</h3> |
| <p>To initialize client you can use code similar to:</p> |
| |
| <div class="highlight"><pre class="codehilite"><code> <span class="kd">private</span> <span class="n">function</span> <span class="nf">initConnection</span><span class="o">():</span><span class="kt">void</span> <span class="o">{</span> |
| <span class="n">mTransport</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">TSocket</span><span class="o">(</span><span class="s">"127.0.0.1"</span><span class="o">,</span> <span class="mi">9090</span><span class="o">);</span> <span class="c1">// we connect to server</span> |
| <span class="n">mTransport</span><span class="o">.</span><span class="na">open</span><span class="o">();</span> |
| <span class="c1">// initialize protocol:</span> |
| <span class="kt">var</span> <span class="nl">protocol:</span><span class="nc">TProtocol</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">TBinaryProtocol</span><span class="o">(</span><span class="n">mTransport</span><span class="o">,</span> <span class="kc">false</span><span class="o">,</span> <span class="kc">false</span><span class="o">);</span> |
| <span class="n">mCalculatorClient</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">CalculatorImpl</span><span class="o">(</span><span class="n">protocol</span><span class="o">);</span> <span class="c1">// finally, we create calculator client instance</span> |
| <span class="o">}</span> |
| |
| </code></pre></div> |
| <p class="snippet_footer">This snippet was generated by Apache Thrift's <strong>source tree docs</strong>: |
| <a href="https://gitbox.apache.org/repos/asf?p=thrift.git;a=blob;hb=HEAD;f=tutorial/as3/src/CalculatorUI.as">tutorial/as3/src/CalculatorUI.as</a> |
| </p> |
| |
| <h3 id="server">Server</h3> |
| <p>The example client above can be tested against a java tutorial server.</p> |
| |
| <h3 id="additional-information">Additional Information</h3> |
| |
| <p>You might find server failing due to out of memory exception. This might happen because of flash crossdomain policy. See |
| next passage on how to fix this.</p> |
| |
| <h3 id="flash-crossdomain-policy">Flash crossdomain policy</h3> |
| |
| <p>Flash does not allow movies to connect to arbitrary servers. This is done for security reasons. To override this |
| restriction, however, servers’ owners can create special file - crossdomain xml file, which lists the rules according to |
| which some flash movies can connect to the server.</p> |
| |
| <p>Details about this behavior are listed in |
| <a href="http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html">Setting up a socket policy file server</a>. |
| Also, you can find a simple python/perl server script to serve this file there. For same host, you can serve |
| crossdomain.xml from any port. So, you can start your RPC servers on ports 9090 and 9091, and serve polisy file from |
| port 9092. To tell flash about this, you can use code from tutorial file:</p> |
| |
| <div class="highlight"><pre class="codehilite"><code> <span class="kd">private</span> <span class="n">function</span> <span class="nf">initSecurity</span><span class="o">():</span><span class="kt">void</span> <span class="o">{</span> |
| <span class="nc">Security</span><span class="o">.</span><span class="na">loadPolicyFile</span><span class="o">(</span><span class="s">"xmlsocket://127.0.0.1:9092"</span><span class="o">);</span> |
| <span class="o">}</span> |
| </code></pre></div> |
| <p class="snippet_footer">This snippet was generated by Apache Thrift's <strong>source tree docs</strong>: |
| <a href="https://gitbox.apache.org/repos/asf?p=thrift.git;a=blob;hb=HEAD;f=tutorial/as3/src/CalculatorUI.as">tutorial/as3/src/CalculatorUI.as</a> |
| </p> |
| |
| <p>Example of crossdomain file, to allow connect to ports 9090 and 9091 from any server:</p> |
| |
| <pre><code> |
| <?xml version="1.0"?> |
| <!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd"> |
| <!-- Policy file --> |
| <cross-domain-policy> |
| <allow-access-from domain="*" to-ports="9090,9091" /> |
| </cross-domain-policy> |
| </code></pre> |
| |
| |
| |
| </div> |
| <div class="container"> |
| <hr> |
| <footer class="footer"> |
| <div class="row"> |
| <div class="span3"> |
| <h3>Links</h3> |
| <ul class="unstyled"> |
| <li><a href="/download">Download</a></li> |
| <li><a href="/developers">Developers</a></li> |
| <li><a href="/tutorial">Tutorials</a></li> |
| </ul> |
| <ul class="unstyled"> |
| <li><a href="/sitemap">Sitemap</a></li> |
| </ul> |
| </div> |
| <div class="span3"> |
| <h3>Get Involved</h3> |
| <ul class="unstyled"> |
| <li><a href="/mailing">Mailing Lists</a></li> |
| <li><a href="http://issues.apache.org/jira/browse/THRIFT">Issue Tracking</a></li> |
| <li><a href="/docs/HowToContribute">How To Contribute</a></li> |
| </ul> |
| </div> |
| <div class="span6"> |
| <a href="http://www.apache.org/"><img src="/static/images/feather.svg" onerror="this.src='/static/images/feather.png';this.onerror=null;" /></a> |
| Copyright © 2020 <a href="http://www.apache.org/">Apache Software Foundation</a>. |
| Licensed under the <a href="http://www.apache.org/licenses/">Apache License v2.0</a>. |
| Apache, Apache Thrift, and the Apache feather logo are trademarks of The Apache Software Foundation. |
| </div> |
| </div> |
| </footer> |
| </div> |
| |
| </body> |
| </html> |