1 import java.net.*;
 2 
 3 public class UdpRecv
 4 {
 5     public static void main(String args[]) throws Exception
 6     {
 7         DatagramSocket ds = new DatagramSocket(3000);
 8         byte [] buf = new byte[1024];
 9         DatagramPacket dp = new DatagramPacket(buf,1024);
10         ds.receive(dp);
11         String strRecv = new String (dp.getData(),0,dp.getLength(),"gb2312")+" from "+dp.getAddress().getHostAddress() + ":"+dp.getPort();
12         System.out.println(strRecv);
13         ds.close();
14     }
15     
16 }

 1 import java.net.*;
 2 
 3 public class UdpSend
 4 {
 5     public static void main(String args[])throws Exception
 6     {
 7         DatagramSocket ds = new DatagramSocket();
 8         String str = "hello ,this is a test";
 9         DatagramPacket dp = new DatagramPacket (str.getBytes(),str.length(),InetAddress.getByName("127.0.0.1"),3000);
10         ds.send(dp);
11         ds.close();
12     }
13 
14 }


posted on 2007-02-08 13:40 -274°C 阅读(121) 评论(0)  编辑  收藏 所属分类: JAVA

专题:Android  iPad  jQuery  Chrome OS

博客园首页  IT新闻  知识库  学英语  Java程序员招聘
标题  
姓名  
主页
验证码 *  
内容(请不要发表任何与政治相关的内容)  
  登录      
每天10分钟,轻松学英语


网站导航:
 

java swing 、 JSP ,mysql, php ,python ,ajax ,javascript 熟悉JQuery 使用过ext.js ,熟悉HTML,CSS前端开发,初涉C++开发。学生时代写过asp ,维护过.net开发的系统,做过J2EE strust应用方面的毕业设计。写过安装包,写过java服务,webservice 。

常用链接

留言簿(17)

随笔分类(207)

JAVA网站

关注的Blog

搜索

  •  

积分与排名

  • 积分 - 441077
  • 排名 - 17

最新评论