[Ace-users] [ace-users] ACE_SOCK_Dgram_Bcast to find server

Robert Thornthwaite Robert.Thornthwaite at iongeo.com
Wed Nov 7 21:32:03 CST 2007

> To ensure that we have proper version/platform/compiler 
> information, please make sure you fill out the appropriate 
> problem report form (PRF),

ACE: 5.5.1
HOST and TARGET: Redhat Linux Release 4 Update 5
$ACE_ROOT/ace/config.h ->config-linux.h
makeinclude/platform_macros.GNU -> platform_linux.GNU

This is an execution question.

> > I am trying to use ACE_SOCK_Dgram_Bcast to find a server 
> > device.   The server responds to the broadcast on my local
> > port that I sent in the broadcast message.   I try to use the 
> > same instance of ACE_SOCK_Dgram_Bcast to receive the response
> > but it does not work.  
> >  
> > I know that if the server responded on a different port 
> > than the one I sent, I could use another ACE_SOCK_Dgram
> > opened on that port and read the response.   But I can't 
> > create another ACE_SOCK_Dgram to read the same local port 
> > that the ACE_SOCK_Dgram_Bcast already has open.
> >  
> > It seems natural to use the ACE_SOCK_Dgram_Bcast to tell 
> > the server what port to respond on.    What is the trick?
> There are examples of ACE_SOCK_Dgram_Bcast in
> ACE_ROOT/tests/SOCK_Dgram_Bcast_Test.cpp
> ACE_ROOT/APG/Misc_IPC/UDP_Broadcast.cpp

I have looked at these examples.  I also have the text books 
APG, NPV1, and NPV2.  I am trying to use this and other things 
with the Reactor but that is not relevant.   
Below is a simple example of what I am trying to do.
I verified with WireShark that the broadcast msg is going
Out to port 8888 and responses are being sent back to port 2077.
The recv() just times out.

Should this not work?

/** Start Example  */
#include "ace/Init_ACE.h"
#include "ace/INET_Addr.h"
#include "ace/SOCK_Dgram_Bcast.h"
#include "ace/SOCK_Dgram.h"
#include "ace/Log_Msg.h"
typedef unsigned short uint16;

int main (int nargs, char ** args)
  char* mpSS_IP_RequestMsg ="Passport Networks Inc.";
  char serialServerResponse[2000];
  ACE_INET_Addr  mMyAddr(ACE_static_cast (uint16, 2077));
  ACE_INET_Addr  mSerialServer_Address;
  ACE_SOCK_Dgram_Bcast mDgram(mMyAddr,ACE_PROTOCOL_FAMILY_INET,0,1);  //
For sending broadcast
  ACE_Time_Value  mtimeout(5,0);
  ssize_t sent = 0;
  ssize_t recvCount = 0;

  for (;;)
    sent = mDgram.send((char*)mpSS_IP_RequestMsg,
                               ACE_static_cast (uint16, 8888));
    recvCount = 0;
    while (recvCount >= 0)
      recvCount = mDgram.recv((void*)&serialServerResponse,
mSerialServer_Address, 0, &mtimeout);
      if (recvCount < 0)
        ACE_DEBUG((LM_DEBUG," Timed out \n"));
      else if (recvCount > 0)
        ACE_DEBUG((LM_DEBUG," OK \n"));
         ACE_DEBUG((LM_DEBUG, " Zero \n"));
/** End Example  */
> There are also examples of ACE_SOCK_Dgram_Mcast that might be 
> relevant, as well, in
> ACE_ROOT/examples/Reactor/Multicast
> ACE_ROOT/examples/Reactor/Ntalker
> Finally, TAO has a service that uses multicast to do 
> basically what you're trying to achieve.  Please see
> TAO/orbsvcs/orbsvcs/IOR_Multicast.h
> TAO/orbsvcs/orbsvcs/IOR_Multicast.cpp
> for details.
> Thanks,
>         Doug

This email and any files transmitted with it are confidential and are intended solely for the use of the individual or entity to whom they are addressed.  If you are not the original recipient or the person responsible for delivering the email to the intended recipient, be advised that you have received this email in error, and that any use, dissemination, forwarding, printing, or copying of this email is strictly prohibited. If you received this email in error, please immediately notify the sender and delete the original.

More information about the Ace-users mailing list