DatagramPacket,DatagramSocket
2024-09-28 22:45:42
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();
} };
最新文章
- JS处理事件小技巧
- Cross join in excel --- Copy from Internet
- 黑苹果-IOS学习的开始
- linux下查看进程占用端口和端口占用进程命令
- Bitmap动画
- C#的扩展方法
- 用MySQL实现分页查询
- dbus
- asp.net 控件 导出 excel
- hdu 2222 Keywords Search ac自动机入门
- Divide Two Integers —— LeetCode
- linux 安装jdk-7u45-linux-x64.tar.gz
- putty完全使用手册--多窗口---git提交---连接数据库--自动日志显示
- 运行错误:应用程序无法启动因为并行配置不正确。the application has failed to start because its side-by-side configuration is incorrect 解决方法
- MySql 中文乱码解决办法
- JavaScript 之DOM&;BOM
- 软件质量与测试——WordCount编码实现及测试
- Vue + WebApi 小项目:构造自己的在线 Markdown 笔记本应用
- springcould 微服务 搭建
- python3对于时间的处理
热门文章
- Codeforces - 220B Little Elephant and Array(莫队模板题)
- Apache-commons.BeanUtils浅析
- OpenNI2安装
- centos 7 服务器网卡做bond
- Java 文件hashCode
- 用MysQL语句怎么进行远程连接数据库
- 培训补坑(day2:割点与桥+强联通分量)
- VMWare虚拟机如何与主机共享文件夹(最容易看懂的讲解)附图~
- 内核中的内存申请:kmalloc、vmalloc、kzalloc、kcalloc、get_free_pages【转】
- python 拼图验证码