You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
707 B
C++
35 lines
707 B
C++
#include "StdAfx.h"
|
|
#include "CYHMudpSend.h"
|
|
/*×é²¥·¢ËÍ*/
|
|
CYHMudpSend::CYHMudpSend()
|
|
{
|
|
|
|
}
|
|
CYHMudpSend::~CYHMudpSend()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
bool CYHMudpSend::initMUDP(const char *IP,u_short Port)
|
|
{
|
|
WSAStartup(MAKEWORD(2, 2), &wsaData);
|
|
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
|
n = 0;
|
|
setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, (char*)&n, sizeof(n));
|
|
|
|
addr.sin_addr.S_un.S_addr = inet_addr(IP);
|
|
addr.sin_family = AF_INET;
|
|
addr.sin_port = htons(Port);
|
|
return true;
|
|
}
|
|
|
|
bool CYHMudpSend::SendData(BYTE* const bufs,int length)
|
|
{
|
|
char* buf = (char*)bufs;
|
|
//sendto(sock, buf, strlen(buf) + 1, 0, (sockaddr*)&addr, sizeof(sockaddr));
|
|
sendto(sock, buf, length, 0, (sockaddr*)&addr, sizeof(sockaddr));
|
|
return true;
|
|
}
|
|
|