udp
来源:互联网 发布:淘宝网男士裤子 编辑:程序博客网 时间:2024/06/11 10:20
package udp;import java.net.DatagramPacket;import java.net.DatagramSocket;public class Udp { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub byte[] buf=new byte[1024]; DatagramSocket ds=new DatagramSocket(8001); DatagramPacket dp=new DatagramPacket(buf, 1024); System.out.println("等待接收数据"); ds.receive(dp); String str=new String(dp.getData(),0,dp.getLength()); System.out.println(str); ds.close(); }}package javasocket;import java.net.DatagramPacket;import java.net.DatagramSocket;import java.net.InetAddress;public class UDPclient { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub DatagramSocket ds=new DatagramSocket(8009); String str="hello world"; DatagramPacket dp=new DatagramPacket(str.getBytes(),str.length(),InetAddress.getByName("localhost"),8001); ds.send(dp); ds.close(); }}
使用UDP协议编写一个网络程序,设置接收端程序的监听端口是8001,发送端发送的数据是“Hello, world”。
阅读全文
0 0
- UDP
- UDP
- udp
- UDP
- UDP
- udp
- UDP
- UDP
- udp
- udp
- UDP
- UDP
- UDP
- UDP
- UDP
- UDP
- udp
- UDP
- 01矩阵
- 高效找出两个List中不同的元素
- 排列组合错排
- memcache、redis原理对比
- jQuery:事件操作(一)
- udp
- 洞穴探测
- idea右侧的maven框没了
- 解决ServerTomcatv7.0Serveratlocalhostfailedtostart.
- Java传参的值传递和引用传递问题(转)
- 【BZOJ】3524 [Poi2014]Couriers && 【BZOJ】2223 [Coci 2009]PATULJCI 主席树
- python中如何对Tensor变量赋值,输出,以placeholder为例
- Spring学习,引用在java类代码中的bean属性
- 名称空间、作用域、装饰器的简单使用