zoukankan      html  css  js  c++  java
  • 抛开BlazeDS,自定义flex RPC

      在做一款webgame,一开始项目使用BlazeDS与后台进行通信。用下来发现BlazeDS做了太多的事情,效率不是很高,所以考虑了一下,自己实现了一个类似于BlazeDS的RPC框架

      客户端flex代码

    public class NetAMF extends NetConnection
    {
       ...sendData()
       ...getData()
    }
    代码
    public function sendData(funName:String,funData:Object=null):void
    {
       ..............

        
    var myRequest:URLRequest=new URLRequest();
        myRequest.method
    =URLRequestMethod.POST;
        myRequest.data
    =realByte;
        myRequest.url
    =serverURL+funName;
        myRequest.contentType
    ="application/x-amf";
        
        
    var myLoader:ZTURLLoader=new ZTURLLoader();
        myLoader.dataFormat
    =URLLoaderDataFormat.BINARY;
        myLoader.addEventListener(Event.COMPLETE,getData);
        ...........
        myLoader.sendDataInfo
    =funName;
        myLoader.load(myRequest);
    }



    public 
    function getData(e:Event):void
    {
         
    var funName:String=(e.currentTarget as ZTURLLoader).sendDataInfo as String
         
    var bytes:ByteArray=ZTURLLoader(e.currentTarget).data as ByteArray;
         
    var obj=bytes.readObject();
         
    var myEvent:ServerEvent=new ServerEvent(SUCCESS,obj,ServerID)
         
    this.dispatchEvent(myEvent);
    }

    服务端通过Servlet读取数据并写回给客户端。 

  • 相关阅读:
    static作用(1)
    Android开发之事件
    安卓开发之intent
    字符串去空
    字符串自实现(一)(mystrcpy,mystrcat,mystrcmp)
    Gin框架介绍及使用
    django model fake
    CentOS7 永久修改系统时间
    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    linux安装mysqlclient库
  • 原文地址:https://www.cnblogs.com/51cto/p/1721277.html
Copyright © 2011-2022 走看看