zoukankan      html  css  js  c++  java
  • 广播即时通信src和des

    package 第十二章;
    
    import java.io.IOException;
    import java.net.DatagramPacket;
    import java.net.InetAddress;
    import java.net.MulticastSocket;
    import java.util.Scanner;
    
    public class GuangBoSrc {
    //	发送广播
    	public static void main(String[] args) throws IOException {
    		InetAddress ip=InetAddress.getByName("230.0.0.1");
    		
    		MulticastSocket multicastSocket=new MulticastSocket(55555);
    		multicastSocket.joinGroup(ip);
    		
    		byte[]b="该起床了!!".getBytes();<pre name="code" class="java">package 第十二章;
    
    import java.io.IOException;
    import java.net.DatagramPacket;
    import java.net.InetAddress;
    import java.net.MulticastSocket;
    import java.net.UnknownHostException;
    
    public class GuangBoDes {
    //	接收广播
    	public static void main(String[] args) throws IOException {
    		InetAddress ip=InetAddress.getByName("2300.0.1");
    		MulticastSocket multicastSocket=new MulticastSocket(55555);
    		multicastSocket.joinGroup(ip);
    		
    		byte[]b=new byte[1024];
    		DatagramPacket packet =new DatagramPacket(b, b.length);
    		multicastSocket.receive(packet);
    		
    		String str=new String(packet.getData(),0,packet.getLength());
    		
    	}
    
    }
    


    DatagramPacket packet=new DatagramPacket(b, b.length, ip, 55555);multicastSocket.send(packet);}}

    
    


  • 相关阅读:
    Google
    LeetCode 664. 奇怪的打印机
    LeetCode 79. 单词搜索
    LeetCode 224. 基本计算器
    Windows 端口映射
    LeetCode 354. 俄罗斯套娃信封问题
    LeetCode 300. 最长递增子序列
    LeetCode 338. 比特位计数
    LeetCode 395. 至少有K个重复的最长子串
    LeetCode 424. 替换后的最长重复字符
  • 原文地址:https://www.cnblogs.com/xiaoqisfzh/p/5959028.html
Copyright © 2011-2022 走看看