コード例 #1
0
  public boolean open(String addr, int port, String bindAddr) {
    try {
      ssdpMultiSock = new MulticastSocket(null);
      ssdpMultiSock.setReuseAddress(true);
      InetSocketAddress bindSockAddr = new InetSocketAddress(port);
      ssdpMultiSock.bind(bindSockAddr);
      ssdpMultiGroup = new InetSocketAddress(InetAddress.getByName(addr), port);
      ssdpMultiIf = NetworkInterface.getByInetAddress(InetAddress.getByName(bindAddr));
      ssdpMultiSock.joinGroup(ssdpMultiGroup, ssdpMultiIf);
    } catch (Exception e) {
      Debug.warning(e);
      return false;
    }

    return true;
  }
コード例 #2
0
 public boolean send(String msg, String bindAddr, int bindPort) {
   try {
     MulticastSocket msock;
     if ((bindAddr) != null && (0 < bindPort)) {
       msock = new MulticastSocket(null);
       msock.bind(new InetSocketAddress(bindAddr, bindPort));
     } else msock = new MulticastSocket();
     DatagramPacket dgmPacket = new DatagramPacket(msg.getBytes(), msg.length(), ssdpMultiGroup);
     // Thnaks for Tho Beisch (11/09/04)
     msock.setTimeToLive(4);
     msock.send(dgmPacket);
     msock.close();
   } catch (Exception e) {
     Debug.warning(e);
     return false;
   }
   return true;
 }