[ActionScript 3.0] NetConnection建立客户端与服务器的双向连接
2016-07-13 15:45
495 查看
一个客户端与服务器之间的接口测试的工具
<?xml version="1.0" encoding="utf-8"?> <!--- - - - - - - - - - - - - - - - - - - - - - - - - * @author:Frost.Yen * @E-mail:871979853@qq.com * @create:2016-7-13上午12:10:20 - - - - - - - - - - - - - - - - - - - - - - - - - - --> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" width="800" height="600" applicationComplete="application1_applicationCompleteHandler(event)"> <fx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.FlexEvent; private var _netConnection:NetConnection; protected function button1_clickHandler(event:MouseEvent):void { if(request.text == ""){ Alert.show("请输入请求地址","温馨提示"); return; } if(action.text == ""){ Alert.show("请输入请求方法","温馨提示"); return; } resultText.text = "connecting..."; initNetConnection(); _netConnection.connect( request.text as String); _netConnection.call(action.text,new Responder(function(result:Object):void{ if (result) { trace("onResult: ",JSON.stringify(result)); resultText.text = "onResult:\n\n"+"ation:"+action.text+"\narguments:"+param.text+"\n\nresult:\n"+JSON.stringify(result); } }),param.text); } private function initNetConnection():void { if (!_netConnection) { trace("initConnection"); _netConnection = new NetConnection(); NetConnection.defaultObjectEncoding = ObjectEncoding.AMF3; _netConnection.addEventListener(NetStatusEvent.NET_STATUS,onStatus); } } public function onStatus(e:NetStatusEvent):void { trace("e.info.code", e.info.code); resultText.text = e.info.code; switch (e.info.code) { case "NetConnection.Connect.Success": case "NetConnection.Connect.Rejected": case "NetConnection.Connect.NetworkChange": case "NetConnection.Connect.Closed": break; case "NetConnection.Call.Failed": case "NetConnection.Connect.Failed": //case "NetConnection.Call.BadVersion"://以不能识别的格式编码的数据包。 trace("onReConnect"); if (_netConnection) { _netConnection.removeEventListener(NetStatusEvent.NET_STATUS,onStatus); _netConnection.close(); _netConnection = null; } break; } } private function test(...arg):void { trace(arg); } protected function application1_applicationCompleteHandler(event:FlexEvent):void { test("1",2,3); } ]]> </fx:Script> <s:HGroup gap="4" top="10" left="5" > <s:Label text="RequestURL:" paddingTop="6"/> <s:TextInput id="request" width="180" text="http://45.63.127.27/web/"/> <s:Label text="action:" paddingTop="6"/> <s:TextInput id="action" width="150" text="LoginAction.index"/> <s:Label text="params:" paddingTop="6"/> <s:TextInput id="param" width="200" text="login,apple,tomyuang"/> <s:Button label="send" click="button1_clickHandler(event)"/> </s:HGroup> <s:TextArea id="resultText" width="790" height="500" left ="5" top="50" selectable="true" /> </s:Application>
相关文章推荐
- php匹配字符串URL并替换为超链接
- 调用手机号码归属地接口 //调用XML格式的数据接口
- iOS获取汉字拼音首字母的方法
- 玩转递归
- maven的setting.xml文件的详解
- CSS+JS控制字体闪烁
- 关于Android Studio中点9图的编译错误问题
- XSS代码参考
- 算法时间复杂度的计算
- java 多线程总结(一) 创建线程的几种方法及对终止线程运行的讨论
- Centos内核升级的三种方法
- leetcode Maximum Size Subarray Sum Equals k
- Python字符串的内置方法
- 损失函数、正则化、交叉验证
- Ubuntu 14.04下安装ns2.35
- js中的异常处理try...catch使用介绍
- 登录mysql出现/var/lib/mysql/mysql.sock不存在
- 【布局】jQuery等高排列插件matchHeight.js
- SQL多表查询和查询一个表中某字段值相同的数据
- Git使用