An AMF implementation based on Node. js

Source: Internet
Author: User

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

 
 
  1. exports.sayHello = function( callback ){  
  2.     return 'Hello World';  

Create a server using node. js and run the AMF service.

 
 
  1. // Define the port, host, and expiration time.
  2. Var listenPort = 8001;
  3. Var listenHost = 'localhost ';
  4. Var timeout = 5000;
  5. // Contains the corresponding server class
  6. Var methods = require ('./amf-methods ');
  7. // Contains the implementation library of amf
  8. Var server = require ('../node-amf/http-Server ');
  9. // Start the service
  10. Server. start (listenPort, listenHost, methods, timeout );

Then, the Flash call AMF method is the same:

 
 
  1. package {  
  2.     import flash.display.Sprite;  
  3.     import flash.net.NetConnection;  
  4.     import flash.net.Responder;  
  5.    
  6.     public class NodeJS_AMF extends Sprite {  
  7.    
  8.         protected var connection:NetConnection;  
  9.         private var responder:Responder;  
  10.         private var host:String = "http://localhost:8001/";  
  11.    
  12.         public function NodeJS_AMF() {  
  13.            responder = new Responder(this.onResult, this.onFault);  
  14.            connection = new NetConnection();  
  15.            connection.connect(host);  
  16.            connection.call("sayHello", responder);  
  17.         }  
  18.    
  19.         private function onResult(e:*):void{  
  20.            trace(e);  
  21.         }  
  22.         private function onFault(e:*):void{  
  23.            trace(e);  
  24.         }  
  25.    
  26.     }  

Have fun!

Http://www.colorhook.com/blog? P = 829

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.