1 // file : TMCast/Member/member.cpp
2 // author : Boris Kolpackov <boris@dre.vanderbilt.edu>
3 #include "ace/Log_Msg.h"
4 #include "ace/Time_Value.h"
5 #include "ace/OS_NS_stdlib.h"
6 #include "ace/OS_NS_unistd.h"
7 #include "ace/OS_NS_stdio.h"
8 #include "ace/OS_NS_time.h"
9 #include "ace/OS_NS_string.h"
11 #include "ace/TMCast/Group.hpp"
16 ACE_TMAIN (int argc
, ACE_TCHAR
* argv
[])
21 if (argc
< 4) throw Args ();
25 if (argv
[1][0] == 'r') receiver
= true;
26 else if (argv
[1][0] == 's') receiver
= false;
29 if (!receiver
) ACE_OS::srand ((u_int
) ACE_OS::time ());
31 ACE_INET_Addr
address (argv
[3]);
33 ACE_TMCast::Group
group (address
, ACE_TEXT_ALWAYS_CHAR (argv
[2]));
37 for (char buffer
[256];;)
39 group
.recv (buffer
, sizeof (buffer
));
41 ACE_DEBUG ((LM_DEBUG
, "%s\n", buffer
));
48 for (unsigned long i
= 0; i
< 1000; i
++)
50 // Sleep some random time around 1 sec.
52 ACE_UINT64 tmpl
= 1000000U;
54 static_cast<unsigned long> (((tmpl
* ACE_OS::rand ()) / RAND_MAX
));
56 // ACE_DEBUG ((LM_DEBUG, "sleeping for %u\n", t));
58 ACE_OS::sleep (ACE_Time_Value (0, t
));
60 ACE_OS::sprintf (buffer
, "message # %lu", i
);
64 group
.send (buffer
, ACE_OS::strlen (buffer
) + 1);
66 catch (ACE_TMCast::Group::Aborted
const&)
68 ACE_ERROR ((LM_ERROR
, "%s has been aborted\n", buffer
));
76 "Usage: member {r|s} <id> <IPv4 mcast address>:<port>\n"));
79 catch (ACE_TMCast::Group::Failed
const&)
82 "Group failure. Perhaps I am alone in the group.\n"));
85 catch (ACE_TMCast::Group::InsufficienSpace
const&)
87 ACE_ERROR ((LM_ERROR
, "Insufficient space in receive buffer.\n"));