Those who have used AMF should know that this is not only efficient, but also greatly relieves the code coupling between the server and the client. Today, I happened to find a node. js-based AMF implementation on github, so I tried some code, hoho ~. The following is an example of communication between Flash and node. js through AMF:
First, define the server class and Method
- exports.sayHello = function( callback ){
- return 'Hello World';
- }
Create a server using node. js and run the AMF service.
- // Define the port, host, and expiration time.
- Var listenPort = 8001;
- Var listenHost = 'localhost ';
- Var timeout = 5000;
- // Contains the corresponding server class
- Var methods = require ('./amf-methods ');
- // Contains the implementation library of amf
- Var server = require ('../node-amf/http-Server ');
- // Start the service
- Server. start (listenPort, listenHost, methods, timeout );
Then, the Flash call AMF method is the same:
- package {
- import flash.display.Sprite;
- import flash.net.NetConnection;
- import flash.net.Responder;
-
- public class NodeJS_AMF extends Sprite {
-
- protected var connection:NetConnection;
- private var responder:Responder;
- private var host:String = "http://localhost:8001/";
-
- public function NodeJS_AMF() {
- responder = new Responder(this.onResult, this.onFault);
- connection = new NetConnection();
- connection.connect(host);
- connection.call("sayHello", responder);
- }
-
- private function onResult(e:*):void{
- trace(e);
- }
- private function onFault(e:*):void{
- trace(e);
- }
-
- }
- }
Have fun!
Http://www.colorhook.com/blog? P = 829