//这是第一段
- package com.Tcp2;
- import java.net.*;
- public class UdpRece2 {
- public static void main(String[] args) throws Exception {
- DatagramSocket ds=new DatagramSocket(10002);
- while(true){
- byte[] buf=new byte[1024];
- DatagramPacket dp=new DatagramPacket(buf,buf.length);
- ds.receive(dp);
- String id=dp.getAddress().getHostAddress();
- String data=new String(dp.getData(),0,dp.getLength());
- System.out.println("IP"+id+"::::"+data);
-
- }
-
- }
- }
复制代码
- //这是第2段
- package com.Tcp2;
- import java.net.*;
- import java.io.*;
- public class Udpsend2 {
- public static void main(String[] args)throws Exception{
- DatagramSocket ds=new DatagramSocket(10002);
-
- BufferedReader bis=new BufferedReader(new InputStreamReader(System.in));
- String line=null;
- while((line=bis.readLine())!=null){
- if("886".equals(line))
- break;
- byte[] buf=line.getBytes();
- DatagramPacket dp=
- new DatagramPacket(buf,buf.length,InetAddress.getByName("192.168.1.113"),10002);
- ds.send(dp);
-
- }
- ds.close();
- }
- }
复制代码 |
|