scorrpeio
January 7th, 2009, 10:43 PM
I am using VC++ in Visual Studio 2005.
I have created the dialog based application. I want to broadcast the message in UDP to know which machines can receive the message & reply me back ( provided those machines are using same exe as I use to broadcast ).
Can anybody tell how to do this???
I could reach up to this...........
int BroadCastInitial;
int iBroadCast = 0;
int rflag = 0, flag =1, len = 0;
BroadCastInitial = UDPSockptr -> SetSockOpt( SO_BROADCAST, &flag, sizeof( int ) );
if ( !BroadCastInitial )
{
wsprintf(m_SocError, "SetSockOpt failed to set SO_BROADCAST:% d", UDPSockptr->GetLastError());
delete UDPSockptr;
UDPSockptr = NULL;
AfxMessageBox ( m_SocError );
}
sockaddr_in m_RemoteAdd;
m_RemoteAdd.sin_family = AF_INET;
m_RemoteAdd.sin_addr.s_addr = inet_addr( "255.255.255.255" );
m_RemoteAdd.sin_port = htonl( INADDR_BROADCAST );
iBroadCast = UDPSockptr -> SendTo("AnyBody here me?",20, (const SOCKADDR*) &m_RemoteAdd, sizeof ( m_RemoteAdd ) );
if ( !iBroadCast )
{
wsprintf(m_SocError, " Broadcasting failed % d", UDPSockptr->GetLastError());
AfxMessageBox ( m_SocError );
}
else
{
AfxMessageBox ( "Broadcasting successful" );
}
I have created the dialog based application. I want to broadcast the message in UDP to know which machines can receive the message & reply me back ( provided those machines are using same exe as I use to broadcast ).
Can anybody tell how to do this???
I could reach up to this...........
int BroadCastInitial;
int iBroadCast = 0;
int rflag = 0, flag =1, len = 0;
BroadCastInitial = UDPSockptr -> SetSockOpt( SO_BROADCAST, &flag, sizeof( int ) );
if ( !BroadCastInitial )
{
wsprintf(m_SocError, "SetSockOpt failed to set SO_BROADCAST:% d", UDPSockptr->GetLastError());
delete UDPSockptr;
UDPSockptr = NULL;
AfxMessageBox ( m_SocError );
}
sockaddr_in m_RemoteAdd;
m_RemoteAdd.sin_family = AF_INET;
m_RemoteAdd.sin_addr.s_addr = inet_addr( "255.255.255.255" );
m_RemoteAdd.sin_port = htonl( INADDR_BROADCAST );
iBroadCast = UDPSockptr -> SendTo("AnyBody here me?",20, (const SOCKADDR*) &m_RemoteAdd, sizeof ( m_RemoteAdd ) );
if ( !iBroadCast )
{
wsprintf(m_SocError, " Broadcasting failed % d", UDPSockptr->GetLastError());
AfxMessageBox ( m_SocError );
}
else
{
AfxMessageBox ( "Broadcasting successful" );
}