簡體   English   中英

組播套接字加入的客戶端IP地址

[英]Multicast Socket Joined Client Ip Address

我正在使用Java的客戶端服務器項目。 我正在使用MulticastSocket。 我必須向選擇性的客戶發送一些消息。 但是我不知道如何加入客戶地址。 誰能幫我一下。

使用下面的代碼,這可能會對您有所幫助。

  private void init() throws IOException {
    DatagramChannel channel = DatagramChannel.open(StandardProtocolFamily.INET);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.configureBlocking(true); //optional
    channel.bind(new InetSocketAddress(5000));
    InetAddress iGroup = InetAddress.getByName("224.0.0.1");
    NetworkInterface intrf = NetworkInterface.getByName("lo"); // lo name could be changed according your requirement
    channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, intrf);

    channel.join(iGroup, intrf);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM