#include <winsock2.h>
#pragma comment(lib,"ws2_32.lib")
using namespace std;
int main()
{
WSAData data;
WSAStartup(MAKEWORD(2, 2), &data);
SOCKET s;
BOOL bRroadcast = TRUE;
s = WSASocket(AF_INET, SOCK_DGRAM, 0, NULL, 0, WSA_FLAG_OVERLAPPED);
setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char*)&bRroadcast, sizeof(BOOL));
SOCKADDR_IN bcast;
bcast.sin_family = AF_INET;
bcast.sin_addr.s_addr = htonl(INADDR_BROADCAST);
bcast.sin_port = htons(6000);
char * sMsg = "this is a test";
sendto(s, sMsg, strlen(sMsg), 0, (SOCKADDR*)&bcast, sizeof(bcast));
closesocket(s);
WSACleanup();
//SO_KEEPALIVE;
getchar();
return 0;
}
#pragma comment(lib,"ws2_32.lib")
using namespace std;
int main()
{
WSAData data;
WSAStartup(MAKEWORD(2, 2), &data);
SOCKET s;
BOOL bRroadcast = TRUE;
s = WSASocket(AF_INET, SOCK_DGRAM, 0, NULL, 0, WSA_FLAG_OVERLAPPED);
setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char*)&bRroadcast, sizeof(BOOL));
SOCKADDR_IN bcast;
bcast.sin_family = AF_INET;
bcast.sin_addr.s_addr = htonl(INADDR_BROADCAST);
bcast.sin_port = htons(6000);
char * sMsg = "this is a test";
sendto(s, sMsg, strlen(sMsg), 0, (SOCKADDR*)&bcast, sizeof(bcast));
closesocket(s);
WSACleanup();
//SO_KEEPALIVE;
getchar();
return 0;
}