// Demonstrate into rams.
Import java.net .*;
Class writeserver {
Public static int SERVERPORT = 666;
Public static int clientport = 999;
Public static int buffer_size = 1024;
Public static datagramsocket Ds;
Public static byte buffer [] = new byte [buffer_size];
Public static void theserver () throws exception {
Int Pos = 0;
While (true ){
Int c = system. In. Read ();
Switch (c ){
Case-1:
System. Out. println ("server quits .");
Return;
Case '/R ':
Break;
Case '/N ':
DS. Send (New datagrampacket (buffer, POs, inetaddress. getlocalhost (), clientport ));
Pos = 0;
Break;
Default:
Buffer [POS ++] = (byte) C;
}
}
}
Public static void theclient () throws exception {
While (true ){
Datagrampacket P = new datagrampacket (buffer, buffer. Length );
DS. Receive (P );
System. Out. println (new string (P. getdata (), 0, P. getlength ()));
}
}
Public static void main (string [] ARGs) throws exception {
If (ARGs. Length = 1 ){
DS = new datagramsocket (SERVERPORT );
Theserver ();
} Else {
DS = new datagramsocket (clientport );
Theclient ();
}
}
}