欢迎来到天天文库
浏览记录
ID:39549246
大小:85.00 KB
页数:19页
时间:2019-07-06
《flex flash与服务器通信的方式》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Flex/Flash支持的数据通讯方式有:httpURLLoaderSOAP(webservice)jsonxmlflashremoting/AMF3xmlsocketsocket(二进制)(自定义协议)高并发的应用中用户状态可以用cookie,不用session如果是多人实时交互如聊天系统,多人在线互动等应用模块 需要用socket进行通讯(与服务器建立长连接),服务器端可以自己写多线程SocketServer也可以基于现有开源的Socketlib进行开发,比如QuickServer和XSocket.读取非实时交互数据如房间列表,游戏列表,用户信息等数据,目前推荐用flashrem
2、otingAMF3协议以下是一个FLASHAS3写的Socket通讯类packagenet{importflash.events.*;importflash.net.*;importflash.utils.*; publicclassmySocketextendsEventDispatcher{privatevarnStatus:int=0;privatevarndx:int=0;privatevarpacket:ByteArray;privateconstREQ_PROCESS:int=4;privatevarpacketlen:uint=0;publicvarport:int;p
3、rivatevarreadpacket:ByteArray;publicvarconnected:Boolean=false;privateconstREQ_DONE:int=3;publicvarhost:String;privatevarpacketbody:ByteArray;privatevarreadbodypos:int=8;privateconstREQ_REQUEST:int=0;privatevarnreadPos:int=0;privateconstPACKET_HEADER_SIZE:int=8;privateconstREQ_BODY:int=2;privat
4、evarnBodyLen:uint=0;privateconstREQ_ERROR:int=5;privateconstPACKET_BUFFER_SIZE:int=16384;privateconstREQ_HEADER:int=1;privatevarsocket:Socket; publicfunctionmySocket(param1:Boolean=false,param2:String="String"){packetlen=0;nStatus=0;nreadPos=0;nBodyLen=0;ndx=0;connected=false;readbodypos=PACKET
5、_HEADER_SIZE;packet=newByteArray();packetbody=newByteArray();readpacket=newByteArray();readpacket.endian=Endian.LITTLE_ENDIAN;packet.endian=Endian.LITTLE_ENDIAN;packetbody.endian=Endian.LITTLE_ENDIAN;return;}//endfunction publicfunctionwriteBegin(param1:int,param2:int=0,param3:int=0):void{param
6、2=SERVER_PACKET_VER;param3=SERVER_SUBPACKET_VER;packetlen=0;packet.position=0;packet.length=0;packetbody.position=0;packetbody.length=0;packet.writeMultiByte("AA","gb2312");packet.writeShort(param1);packet.writeByte(param2);packet.writeByte(param3);return;}//endfunction publicfunctionwriteByte(
7、param1:int):void{packetlen=packetlen+1;packetbody.writeByte(param1);return;}//endfunction publicfunctionwriteInt(param1:int):void{packetlen=packetlen+4;packetbody.writeInt(param1);return;}//endfunction publicfunctiongetbodylen():i
此文档下载收益归作者所有