/** Sender */Public void send () throws exception {system. out. println ("send .............. "); // obtain the address instance inetaddress target = inetaddress of the target machine. getbyname ("localhost"); // send the datagram mongoramsocket DS = new mongoramsocket (8888) from Port 8888; string Hello = "Hello, I am come in! "; // Convert data to byte type byte [] Buf = hello. getbytes (); // package the data in the Buf buffer. The target port is 8889 datagrampacket op = new datagrampacket (BUF, Buf. length, target, 8889); // send Ds. send (OP); DS. close (); system. out. println ("Send end. "+ target. gethostaddress ();}/** receiver */Public void receive () throws exception {system. out. println ("receive ........ "); byte [] Buf = new byte [1000]; // monitor port 8889, mongoramsocket DS = new mongoramsocket (8889 ); // create an instance for receiving a datagram; its rampacket IP address is new datagrampacket (BUF, Buf. length); While (true) {// load the received datagram into the IP address Ds. receive (IP); system. out. println (new string (BUF ));}}