[ActionScript 3.0] NetConnection建立用戶端與伺服器的雙向串連

來源:互聯網
上載者:User

標籤:

一個用戶端與伺服器之間的介面測試的工具

 

<?xml version="1.0" encoding="utf-8"?><!--- - - - - - - - - - - - - - - - - - - - - - - - -* @author:Frost.Yen* @E-mail:[email protected]* @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>

 

[ActionScript 3.0] NetConnection建立用戶端與伺服器的雙向串連

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.