All Apache Thrift tutorials require that you have:
Generated the tutorial.thrift and shared.thrift files as discussed here
thrift -r --gen as3 tutorial.thrift
Followed all prerequesets listed
To initialize client you can use code similar to:
private function initConnection():void {
mTransport = new TSocket("127.0.0.1", 9090); // we connect to server
mTransport.open();
// initialize protocol:
var protocol:TProtocol = new TBinaryProtocol(mTransport, false, false);
mCalculatorClient = new CalculatorImpl(protocol); // finally, we create calculator client instance
}
The example client above can be tested against a java tutorial server.
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.
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.
Details about this behavior are listed in Setting up a socket policy file server. 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:
private function initSecurity():void {
Security.loadPolicyFile("xmlsocket://127.0.0.1:9092");
}
Example of crossdomain file, to allow connect to ports 9090 and 9091 from any server:
<?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>