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读取数据并写回给客户端。 

  • 相关阅读:
    上海第八中学 shader
    http://www.riemers.net/
    手写板驱动
    使用dos 作为中介实现cpython 和c# 交互
    判断一个点是不是在三角形中 用面积算法
    Python os.chmod
    Python 的stat 模块
    文件格式说明
    win7 一切软件都安装不上 解决 把他卸掉
    执行力
  • 原文地址:https://www.cnblogs.com/51cto/p/1721277.html
Copyright © 2011-2022 走看看