本帖最后由 程序爱好者 于 2014-5-12 11:17 编辑
- import java.net.*;
- import java.io.*;
- public class UdpSend2 {
- public static void main(String[] args) throws Exception
- {
- DatagramSocket ds=new DatagramSocket();
- BufferedReader bw=new BufferedReader(new InputStreamReader(System.in));
- String line=null;
- while((line=bw.readLine())!=null)
- {
- if("886".equals(line)){
- break;
- }
- byte[] buf=line.getBytes();
- DatagramPacket dp=new DatagramPacket(buf,buf.length,InetAddress.getByName("192.168.1.104"),10001);
- ds.send(dp);
- ds.close();
- }
- }
- }
- import java.net.*;
- import java.io.*;
- public class UdpRece2 {
- public static void main(String[] args) throws Exception
- {
- DatagramSocket ds=new DatagramSocket();
- while(true)
- {
- byte[] buf=new byte[1024];
- DatagramPacket dp=new DatagramPacket(buf,buf.length);
- ds.receive(dp);
- String ip=dp.getAddress().getHostAddress();
- String data=new String(buf,0,dp.getLength());
- System.out.println(ip+"::"+data);
- }
- }
- }
复制代码
看了毕老师的视频,将到这UDP这方面 运行的时候都是用dom命令输入测试的,如果用MyEclipse怎么测试,先运行哪个 具体怎么操作? |
|