/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// This example is from the ACE Programmers Guide.
////  Chapter: "IPC SAP" (Interprocess Communication Mechanisms in ACE).
//// For details please see the guide at
//// http://www.cs.wustl.edu/~schmidt/ACE.html
////  AUTHOR: Umar Syyid ([email protected])
//// and Ambreen Ilyas ([email protected])
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Example 6
#define DEFAULT_MULTICAST_ADDR "224.9.9.2"
#define TIMEOUT 5
#include "ace/SOCK_Dgram_Mcast.h"
#include "ace/OS.h"

class Sender_Multicast{
public:
Sender_Multicast(int port):
 local_addr_((u_short)0),dgram_(local_addr_),
 multicast_addr_(port,DEFAULT_MULTICAST_ADDR){}

//Method which uses a simple datagram component to send data to the multicast group.
int send_to_multicast_group(){
   //Convert the information we wish to send into network byte order
 mcast_info= htons (1000);

 // Send multicast
 if(dgram_.send
    (&mcast_info, sizeof (mcast_info), multicast_addr_)==-1)
    return -1;

 ACE_DEBUG ((LM_DEBUG,
              "%s; Sent multicast to group.  Number sent is %d.\n",
              __FILE__,
              mcast_info));
  return 0;
}

private:
 ACE_INET_Addr multicast_addr_;
 ACE_INET_Addr local_addr_;
 ACE_SOCK_Dgram dgram_;
 int mcast_info;
};
 

int main(int argc, char*argv[]){
Sender_Multicast m(2000);
if(m.send_to_multicast_group()==-1) {
 ACE_DEBUG((LM_ERROR,"Send to Multicast group failed \n"));
 exit(-1);
 }
else
 ACE_DEBUG((LM_DEBUG,"Send to Multicast group succesful \n"));
}

 Next Example