1 import java.net.*;
 2 import java.io.*;
 3 class  UdpSend2
 4 {
 5     public static void main(String[] args) throws Exception
 6     {
 7         DatagramSocket ds = new DatagramSocket();
 8         BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in));
 9         String line = null;
10         while((line=bufr.readLine())!=null)
11         {
12             if("886".equals(line))
13                 break;
14             byte[] buf = line.getBytes();
15             DatagramPacket dp = 
16         new DatagramPacket(buf,buf.length,InetAddress.getByName("192.168.1.255"),10001);
17             ds.send(dp);
18         }
19         ds.close();
20     }
21 }
22 class  UdpRece2
23 {
24     public static void main(String[] args) throws Exception
25     {
26         DatagramSocket ds = new DatagramSocket(10001);
27         while(true)
28         {
29             byte[] buf = new byte[1024];
30             DatagramPacket dp = new DatagramPacket(buf,buf.length);
31             ds.receive(dp);
32             String ip = dp.getAddress().getHostAddress();
33             String data = new String(dp.getData(),0,dp.getLength());
34             System.out.println(ip+"::"+data);
35         }
36     }
37 }

 

相关文章:

  • 2021-11-21
  • 2021-08-26
  • 2021-06-09
猜你喜欢
  • 2022-02-11
  • 2021-05-27
  • 2021-12-27
  • 2021-10-06
  • 2021-09-22
  • 2021-09-07
  • 2021-05-29
相关资源
相似解决方案