`
wenson
  • 浏览: 1043316 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Remoting by NetConnection

阅读更多

一般在使用Flash Remoting功能的時候
都是安裝Remoting Library AS1、AS2 Component來用
其實是可以直接用NetConnection呼叫Remoting的

因為AMF在Flash Player中的Serialize、Deserialize動作
都是透過NetConnection於底層完成,並非寫在AS
就是因為寫在底層,所以AMF會比其他格式來得更有效率

NetConnection具有兩種連線方式,決定於要連線URL通訊協定
對FlashCom RTMP連線是像Socket持續性即時連線
對Remoting Server HTTP則是非持續性連線

不過兩者都是以AMF格式作序列化

以下示範用NetConnection呼叫Remoting方式:

ActionScript Code:

  1. var nc:NetConnection = new NetConnection();
  2. var url:String = "http://192.168.0.10:8084/FlashRemoting/gateway";
  3. nc.onResult = function(data) {
  4.         trace("onResult : "+data);
  5. };
  6. nc.onStatus = function(info) {
  7.         trace("onStatus : "+info);
  8.         for (var i in info) {
  9.                 trace("info["+i+"] : "+info[i]);
  10.         }
  11. };
  12. nc.connect(url);
  13. nc.call("swl.NewClass.Test", nc, 11);
  14. //output: onResult : Test() with Number : 11.0
 
Java Class Code:
  1. package swl;
  2. public class NewClass {
  3.     
  4.     public NewClass() {
  5.     }
  6.     
  7.     public java.util.Map Test(java.util.Map map) {
  8.         return map;
  9.     }
  10.     public String Test(java.util.ArrayList arraylist) {
  11.         return "Test() with ArrayList : " + arraylist;
  12.     }
  13.     public String Test(String str) {
  14.         return "Test() with String : " + str;
  15.     }
  16.     public String Test(String[] str) {
  17.         return "Test() with String Array : " + str;
  18.     }
  19.     public String Test(Number num) {
  20.         return "Test() with Number : " + num;
  21.     }
  22.     public String Test(boolean bo) {
  23.         return "Test() with boolean : " + bo;
  24.     }
  25.     public String Test() {
  26.         return "Test() no arguments";
  27.     }
  28. }

 

此文收藏自Ticore‘s Blog: http://ticore.blogspot.com/2005/09/remoting-by-netconnection.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics