#include #include #include #include #include #include #define DEST_PORT 4567 #define SOURCE_PORT 0 #define DEST_IP_ADDRESS "234.5.6.7" void outDebug(const String &string); void main(int argc,char **argv) { WSASystem wsaSystem; SocketAddress socketAddressLocal; Socket socket; if(!socket.create(Socket::DomainInternet,Socket::SocketDGram,Socket::ProtocolNone)) { outDebug("[Socket creation failed]"); return; } if(!socket.reuseAddress(true)) { outDebug("[Error setting option REUSEADDR.]"); socket.destroy(); return; } outDebug("Socket created."); socketAddressLocal.family(AF_INET); socketAddressLocal.internetAddress(InternetAddress()); socketAddressLocal.port(htons(SOURCE_PORT)); if(!socket.bind(socketAddressLocal)) { outDebug("Bind failed."); socket.destroy(); return; } outDebug("Socket is bound."); if(!socket.setMulticastTTL(2)) { outDebug("[Error setting option SET_MULTICAST_TTL.]"); socket.destroy(); return; } INETSocketAddress inetSocketAddress; inetSocketAddress.family(AF_INET); inetSocketAddress.port(htons(DEST_PORT)); inetSocketAddress.internetAddress(InternetAddress(DEST_IP_ADDRESS)); String strSend("Multicast Data"); while(true) { if(!socket.sendTo(strSend.str(),strSend.length(),inetSocketAddress)) { outDebug("Send Failed."); socket.destroy(); return; } else { outDebug("Data sent."); } ::Sleep(10000); } socket.destroy(); } void outDebug(const String &string) { String outString(string+String("\n")); cout << ((String&)string).str() << endl; ::OutputDebugString(outString.str()); }