コード例 #1
0
  /** INTERNAL: Send out an announcement that we are here. */
  public void announceSession() {
    rcm.logDebug("sending_announcement", (Object[]) null);

    ServiceAnnouncement outMsg = new ServiceAnnouncement(rcm.getServiceId());
    byte[] outBytes = outMsg.toBytes();

    try {
      // Create a packet to send and send it out to everyone listening
      DatagramPacket sendPacket =
          new DatagramPacket(
              outBytes,
              outBytes.length,
              InetAddress.getByName(multicastGroupAddress),
              multicastPort);
      getCommunicationSocket().send(sendPacket);

      Object[] args = null;
      rcm.logInfo("announcement_sent", args);

    } catch (Exception ex) {
      // We got an exception. Map it to an RCM exception and call the handler
      DiscoveryException discoveryEx = DiscoveryException.errorSendingAnnouncement(ex);
      rcm.handleException(discoveryEx);
    }
  }
コード例 #2
0
 /** INTERNAL: Create the multicast socket and join the multicast group. */
 public void createCommunicationSocket() {
   Object[] args = {multicastGroupAddress, "" + multicastPort};
   rcm.logDebug("initializing_discovery_resources", args);
   if (communicationSocket == null) {
     try {
       communicationSocket = new MulticastSocket(multicastPort);
       communicationSocket.setTimeToLive(getPacketTimeToLive());
       communicationSocket.joinGroup(InetAddress.getByName(multicastGroupAddress));
     } catch (IOException ex) {
       // Either we couldn't create the socket or we couldn't join the group
       DiscoveryException discoveryEx = DiscoveryException.errorJoiningMulticastGroup(ex);
       rcm.handleException(discoveryEx);
     }
   }
 }