debug16_4.java

来自「北京大学出版社的」· Java 代码 · 共 38 行

JAVA
38
字号
package questions.c16;
import java.io.*;
import java.net.*;
public class Debug16_4 {
   private InetAddress host;
   private int port;
   public Debug16_4( InetAddress host, int port ) {
      this.host = host;
      this.port = port;
   }
   public void run() {
      try {
         DatagramSocket client = new DatagramSocket();
         String testData = "Test Data";
         DatagramPacket outDgp
            = new DatagramPacket( testData.getBytes(),
                                  testData.length() );
         client.send( outDgp );
         byte[] buffer = new byte[256];
         DatagramPacket inDgp = new DatagramPacket();
         client.receive( inDgp );
         client.close();
      }
      catch( IOException iox ) {
         iox.printStackTrace();
      }
   }
   public static void main( String[] args ) {
      try {
         InetAddress host = InetAddress.getLocalHost();
         Debug16_4 client = new Debug16_4( host, 8189 );
         client.run();
      }
      catch ( UnknownHostException uhx ) {
         uhx.printStackTrace();
      }
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?