1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| import java.io.IOException; import java.net.*; import java.util.Scanner;
public class demol26 { public static void main(String[] args) throws IOException { DatagramSocket ds=new DatagramSocket(); Scanner sc=new Scanner(System.in); while (true){ System.out.println("输入你要发的内容:"); String s=sc.nextLine(); if ("886".equals(s)){ break; } byte[] bytes = s.getBytes(); InetAddress sd=InetAddress.getByName("127.0.0.1"); int port=10086; DatagramPacket dp=new DatagramPacket(bytes,bytes.length,sd,port); ds.send(dp); } ds.close();
} }
|