Java and flash the TCP communications (XMLSocket)

Related Tags:

  This afternoon on a flash in the category XMLSocket encountered small, so out of it 
  Flash code: 
  Var mySocket: XMLSocket = new XMLSocket (); 
  / / Local address, port 5000 
  MySocket.connect ( "localhost", 5000); 
  / / Events 
  MySocket.onConnect = function (myStatus) 
  ( 
  If (myStatus) 
  ( 
  Trace ( "connect success!"); 
  / / Send a message 
  MySocket.send ( "soda" "\ n"); 
  Trace ( "Send success!"); 
  ) 
  Else 
  ( 
  Trace ( "Connection failed!"); 
  ) 
  ); 
  / / Receive information events 
  MySocket.onData = function (msg: String) 
  ( 
  Trace ( "received the text:" msg); 
  ) 
--------------------------------------------------
  Java code: 
  Import java.net .*; 
  Import java.io. *; 


  Public class Server 
  ( 
  Public static void main (String [] args) throws Exception 
  ( 
  / / Set up the server (TCP) 
  ServerSocket ss = new ServerSocket (5000); 
  System.out.println ( "waiting for connecting ......."); 
  Socket sk = ss.accept (); 
  System.out.println ( "a successful connection ......"); 
  / / Build character stream 
  BufferedReader br = new BufferedReader (new InputStreamReader (sk.getInputStream ())); 
  System.out.println ( "Get BufferedReader ......"); 
  System.out.println ( "Get inside the content of ......"); 
  / / Wait to receive information 
  String name = br.readLine (); 

  / / Send a message 
  PrintWriter os = new PrintWriter (sk.getOutputStream ()); 
  Os.println ( "soda, soda" "\ 0"); 
  Os.flush (); 
  Os.close (); 
  System.out.println ( ":" name); 
  ) 
  }------------------------------------------------- ---------- 
  It is worth noting that mySocket.send ( "soda" "\ n"); this sentence, if not increased after the "\ n", java server is not immediately receive information.    Because br.readLine () is to accept his party, if there is no "\ n", it could not find newline, will be waiting there has been eavesdropping will not respond (Khan ~ ~ ~ I have been here is the card long) 

Related articles:

Several in ASP.Net use CSS personalized interface method
  Brown read the article, through different pages dynamically loaded CSS personalized interfaces (such as personalized blog interface) have the following methods    Method 1:    HtmlGenericControl definition was not specific. NET Framework Class HTML server that controls ...
Simple and practical skills of the Web-based form effects
  A color dotted line forms    <style Type="text/css">    <! --    . Tab1 (    Border-top-width: thin;    Border-right-width: thin;    Border-bottom-width: thin;    Border-left-width: thin;  &...
FLASH in achieving functional Tooltip
  FLEX, in the components function with Tooltio Unfortunately, FLASH MX2004 components not provided, the time when you need to be developed, but Button components for the operation of the incident only a mouse click (click) a, how to accept the mouse (onRollOver / onMouseOver) and skidded off ...
Using Web standards establishment of the first three days: Definition Language Encoding
  The third step is to define your language code, something like this:    <meta Http-equiv="Content-Type" content="text/html; charset=gb2312" />    In order to be the correct interpretation and browser through the W3C validation code, all the XHT...
Yuan HONGGANG: Ajax is only a transitional technology
  Abstract: Ajax is a kind of old wine in a new bottle transitional technology, I believe that in the next one to two years, will be replaced by new technology, a way to solve problems and the means to create a highly abstract framework can be resolved programmes, and JSF is an extensible frame...