熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

Flex Socket與Java通訊客戶端寫法

2013-11-23 19:34:42  來源: Java核心技術 

  <?xml version= encoding=utf?>

  <mx:Application xmlns:mx= layout=absolute

  fontSize= creationComplete=initApp(); >

  <mx:Script>

  <![CDATA[

  import ntrolsAlert;

  import Socket;

  import flashutilsByteArray;

  import flasheventsKeyboardEvent;

  //import flashsystemSecurity;

  private var socket:Socket=new Socket();

  internal function readConf():void

  {

  //   var host:String = client_paralastResultSocketClienthost;

  }

  internal function initApp():void

  {

  //    SecurityloadPolicyFile();

  /// Alert(host);

  //var port:int = client_paralastResultSocketClientport;

  //Alert(port);

  myInputaddEventListener(KeyboardEventKEY_DOWNsendMessageUseEnterKey);

  nnect();

  socketaddEventListener(EventCONNECTfunConnect);

  socketaddEventListener(EventCLOSEfunClose);

  socketaddEventListener(ProgressEventSOCKET_DATAfunSocket);

  }

  internal function funConnect(event:Event):void

  {

  myTexttext+=連接已建立 \n;

  }

  internal function funClose(event:Event):void

  {

  myTexttext+=連接已關閉 \n;

  }

  internal function sendMessage(msg:String):void

  {

  var message:ByteArray=new ByteArray();

  messagewriteUTFBytes(msg+\n);

  socketwriteBytes(message);

  socketflush();

  myInputtext=;

  }

  internal function funSocket(event:ProgressEvent):void

  {

  var msg:String=;

  while(socketbytesAvailable)

  {

  msg+=socketreadMultiByte(socketbytesAvailableutf);

  var arr:Array=msgsplit(\n);

  for(var i:int=;i<arrlength;i++)

  {

  if(arr[i]length>)

  {

  var myPattern:RegExp=/\r/;

  arr[i]=arr[i]replace(myPattern);

  myTexttext+=arr[i]+\n;

  }

  }

  myTextverticalScrollPosition = myTextmaxVerticalScrollPosition;//滾動到最下面

  }

  }

  private function sendMessageUseEnterKey(evt:KeyboardEvent):void{

  if(evtkeyCode==){

  sendMessage(myNametext+:+myInputtext);

  }

  }

  ]]>

  </mx:Script>

  <!<mx:HTTPService id=client_para url=confxml useProxy=false/>>

  <mx:Panel width= height= horizontalCenter= verticalCenter= layout=absolute verticalAlign=middle horizontalAlign=center>

  <mx:TextArea y= width= height= id=myText horizontalCenter=/>

  <mx:TextInput x= y= width= id=myInput/>

  <mx:Button label=Send id=myBtn click=sendMessage(myNametext+:+myInputtext) x= y=/>

  <mx:TextInput width= text=Name id=myName verticalCenter= horizontalCenter=/>

  </mx:Panel>

  </mx:Application>


From:http://tw.wingwit.com/Article/program/Java/hx/201311/27122.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.