Thanks for the help.
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@abc.com> wrote in message
news:euapus$sn4$1@daniel-new.mch.sbs.de...
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