首页 > 其他 > 详细

聊天软件项目UDP升级版

时间:2016-04-10 00:59:54      阅读:204      评论:0      收藏:0      [点我收藏+]
 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 }

 

聊天软件项目UDP升级版

原文:http://www.cnblogs.com/hellochennan/p/5373199.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!