⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example1receiver.java

📁 JAVA分布式程序学习的课件(全英文)
💻 JAVA
字号:
import java.io.*; 
import java.net.*; 

/**
 * This example illustrates the basic syntax for basic multicast.
 * @author M. L. Liu
 */
public class Example1Receiver {

// An application which joins a multicast group and
// receives a  single message sent to the group.
   static MulticastSocket s;
   static InetAddress group;
   public static void main(String[] args) {
      try {      
         // join a Multicast group and send the group salutations
         group = InetAddress.getByName("239.1.2.3");
         s = new MulticastSocket(3456);
         System.out.println("Joined group at 239.1.2.3 port 3456");
         s.joinGroup(group);
         byte[] buf = new byte[100];
         DatagramPacket recv = new DatagramPacket(buf, buf.length);
         s.receive(recv);
         System.out.println(new String(buf));
         s.close();
       }
       catch (Exception ex) { // here if an error has occurred
          ex.printStackTrace( ); 
       }
    }// end main
}// end class
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -