package test;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress; public class Server { public static void main(String[] args) throws IOException {
DatagramSocket ds=new DatagramSocket(3000);
String str="Hello";
DatagramPacket dp=new DatagramPacket(str.getBytes(),str.length(),InetAddress.getByName("localhost"),9000);
ds.send(dp);
ds.close();
} }

package test;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket; public class Client{
public static void main(String args[]) throws IOException{
DatagramSocket ds=new DatagramSocket(9000);
byte b[]=new byte[1024];
DatagramPacket dp=new DatagramPacket(b,1024);
ds.receive(dp);
String str=new String(dp.getData(),0,dp.getLength())+"from"+dp.getAddress().getHostAddress()+":"+dp.getPort();
System.out.println(str);
ds.close();
} };

最新文章

  1. JS处理事件小技巧
  2. Cross join in excel --- Copy from Internet
  3. 黑苹果-IOS学习的开始
  4. linux下查看进程占用端口和端口占用进程命令
  5. Bitmap动画
  6. C#的扩展方法
  7. 用MySQL实现分页查询
  8. dbus
  9. asp.net 控件 导出 excel
  10. hdu 2222 Keywords Search ac自动机入门
  11. Divide Two Integers —— LeetCode
  12. linux 安装jdk-7u45-linux-x64.tar.gz
  13. putty完全使用手册--多窗口---git提交---连接数据库--自动日志显示
  14. 运行错误:应用程序无法启动因为并行配置不正确。the application has failed to start because its side-by-side configuration is incorrect 解决方法
  15. MySql 中文乱码解决办法
  16. JavaScript 之DOM&BOM
  17. 软件质量与测试——WordCount编码实现及测试
  18. Vue + WebApi 小项目:构造自己的在线 Markdown 笔记本应用
  19. springcould 微服务 搭建
  20. python3对于时间的处理

热门文章

  1. Codeforces - 220B Little Elephant and Array(莫队模板题)
  2. Apache-commons.BeanUtils浅析
  3. OpenNI2安装
  4. centos 7 服务器网卡做bond
  5. Java 文件hashCode
  6. 用MysQL语句怎么进行远程连接数据库
  7. 培训补坑(day2:割点与桥+强联通分量)
  8. VMWare虚拟机如何与主机共享文件夹(最容易看懂的讲解)附图~
  9. 内核中的内存申请:kmalloc、vmalloc、kzalloc、kcalloc、get_free_pages【转】
  10. python 拼图验证码