Re: UDP broadcasting/multicasting problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi
Thanks for the help.

This code works on my subnet, but are you able to get it working across
subnets ?

When i try this on my machine ip : 132.186.192.254
and another machine with ip : 132.186.103.107

it doesnt work :-(

any way out ?

thanks
SKJ

"AliR (VC++ MVP)" <AliR@xxxxxxxxxxxxx> wrote in message
news:iPbOh.3431$Kd3.3185@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I had to write a program that does what you are trying to do. But mine
wouldn't blindly broadcast messages, it would wait for someone to ask for
it. I first did UDP broadcasts (255.255.255.255) but realized that most
places that my application is being installed at has broadcasting turned
off.

So here is how I did it. I create a receiving multicast socket on the
server(example address 224.1.12.34 Port 12345), then the client creates
the sending multicast socket and sends a message through it to the same
address and port (address 224.1.12.34 Port 12345). The server receives
the message and packs it's IP in a message and sends it back through the
same multicast socket using the address and port it gets from the
ReceiveFrom call. The client then takes the IP from the message and
connects a TCP socket back to the server.

Here is how I create my sockets:

///////////////////////////////////////////////////////////////////////////////////
//this will get called from the server code

///////////////////////////////////////////////////////////////////////////////////
BOOL LSSocket::CreateReceivingMulticastSocket(LPCTSTR strGroupIP, UINT
nGroupPort,DWORD &Error)
{
/* Create socket for receiving packets from multicast group */
if(!CAsyncSocket::Create(nGroupPort, SOCK_DGRAM,FD_READ))
{
if (!CreateSocket(nGroupPort,Error))
{
Error = GetLastError();
return FALSE;
}
}

BOOL bMultipleApps = TRUE; /* allow reuse of local port if needed */
SetSockOpt(SO_REUSEADDR, (void*)&bMultipleApps, sizeof(BOOL),
SOL_SOCKET);

/* Join the multicast group */
m_mrMReq.imr_multiaddr.s_addr = inet_addr(strGroupIP); /* group addr */
m_mrMReq.imr_interface.s_addr = htons(INADDR_ANY); /* use default */
if(setsockopt(m_hSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char FAR
*)&m_mrMReq, sizeof(m_mrMReq)) < 0)
{
Error = GetLastError();
return FALSE;
}

return TRUE;
}

BOOL LSSocket::CreateSocket(int Port,DWORD &Error)
{
m_UDP = TRUE;
if (CAsyncSocket::Create(Port,SOCK_DGRAM))
{
int Value = 1;
SetSockOpt(SO_BROADCAST,&Value,sizeof(int));
SetTTL(110,Error);
return TRUE;
}
Error = MAKELONG(1,GetLastError());
return FALSE;
}

///////////////////////////////////////////////////////////////////////////////////
//this gets called from the client code.

///////////////////////////////////////////////////////////////////////////////////
BOOL LSSocket::CreateSendingSocket(UINT nTTL, BOOL bLoopBack,DWORD &Error)
{
if(!Create(0, SOCK_DGRAM)) // Create an unconnected UDP socket
{
Error = GetLastError();
return FALSE;
}

SetTTL(nTTL,Error); // Set Time to Live as specified by user

SetLoopBack(bLoopBack); // Enable/Disable Loopback
m_UDP = TRUE;
return TRUE;
}


you must use SendTo and ReceiveFrom calls to send and receive message when
m_UDP == TRUE;

AliR.

"Sinu James" <abc@xxxxxxx> wrote in message
news:euapus$sn4$1@xxxxxxxxxxxxxxxxxxxxxxxx
Hello ,

What I want is a server on my LAN to broadcast its address to all
machines on the LAN.
Using UDP broadcasting or multicasting I was hoping to send the server
information across the LAN so that interested clients can establish
connections.

However, all broadcasts and multicast sample code dont seem to work on my
LAN (which I have tested successfully on other networks).
The router may not be configured for UDP broadcasts.

Is there any other alternative for the server to broadcast this info to
the clients without a central server mechanism?

Certain applications are able to do on the same LAN and they "seem" to
use UDP connections. :-(

{windows Firewall is disabled}

thanks in advance
SKJ








.



Relevant Pages

  • Re: UDP broadcasting/multicasting problem
    ... What I want is a server on my LAN to broadcast its address to all machines ... My client starts up a listener on a different known port. ...
    (microsoft.public.vc.mfc)
  • UDP broadcasting/multicasting problem
    ... What I want is a server on my LAN to broadcast its address to all machines ... Using UDP broadcasting or multicasting I was hoping to send the server ... Is there any other alternative for the server to broadcast this info to the ...
    (microsoft.public.vc.mfc)
  • Re: UDP broadcasting/multicasting problem
    ... What I want is a server on my LAN to broadcast its address to all ... Using UDP broadcasting or multicasting I was hoping to send the server ... My client starts up a listener on a different known port. ...
    (microsoft.public.vc.mfc)
  • Re: UDP broadcasting/multicasting problem
    ... I create a receiving multicast socket on the ... //this will get called from the server code ... What I want is a server on my LAN to broadcast its address to all machines ...
    (microsoft.public.vc.mfc)
  • Re: Server name: What to enter?
    ... number you have specified in WME output properties for pull (WME can find ... LAN I.P. which is different to my outside I.P. Which is now the DynDNS ... Player and get the broadcast live. ... Let's address that first to see if a push to a server is what you need ...
    (microsoft.public.windowsmedia.encoder)