网络编程
UDP协议 不管接收端是否存在都会执行发生操作,并且接收端不会做出响应,` public class Demo { public static void main ( String [ ] args ) throws IOException { //DatagramSocket封装了upd协议的相关方法 DatagramSocket ds = new DatagramSocket ( ) ; String s = "hello" ; InetAddress ip = InetAddress . getByName ( "127.0.0.1" ) ; //字节数组,长度,长度,ip,端口号 System . out . println ( ip ) ; DatagramPacket dp = new DatagramPacket ( s . getBytes ( ) , 0 , s . getBytes ( ) . length , ip , 8888 ) ; ds . send ( dp ) ; //发送要发的数据 ds . close ( ) ; } } public class Receive { public static void main ( String [ ] args ) throws IOException { //服务器没有指定ip默认本地主机,要指定端口号