Flash code: var mysocket: xmlsocket = new xmlsocket ();
// Local address, port 5000
Mysocket. Connect ("localhost", 5000 );
// Event
Mysocket. onconnect = function (mystatus)
{
If (mystatus)
{
Trace ("connection successful! ");
// Send information
Mysocket. Send ("soda" + "\ n ");
Trace ("sent successfully! ");
}
Else
{
Trace ("connection failed! ");
}
};
// Accept information events
Mysocket. ondata = function (MSG: string)
{
Trace ("received content:" + MSG );
}
--------------------------------------------------
Java code:
Import java.net .*;
Import java. Io .*;
Public class Server
{
Public static void main (string [] ARGs) throws exception
{
// Create a server (TCP)
Serversocket Ss = new serversocket (5000 );
System. Out. println ("waiting for connection .......");
Socket Sk = ss. Accept ();
System. Out. println ("connection successful ......");
// Create a producer stream
Bufferedreader BR = new bufferedreader (New inputstreamreader (SK. getinputstream ()));
System. Out. println ("Get bufferedreader ......");
System. Out. println ("Get the content ......");
// Wait for receiving information
String name = Br. Readline ();
// Send information
Printwriter OS = new printwriter (SK. getoutputstream ());
OS. println ("soda, soda" + "\ 0 ");
OS. Flush ();
OS. Close ();
System. Out. println ("content:" + name );
}
}
-----------------------------------------------------------
It is worth noting that mysocket. Send ("soda" + "\ n ");
If "\ n" is not added, the Java Server cannot accept the information immediately.
Because Br. Readline () accepts a row, if "\ n" is not found,
If it cannot find the line break symbol, it will listen and wait there without responding.
(Khan ~~~ I am stuck here for a long time)