|
udp 打log 客户端.超简单的
void SOCKETRACE(char *buf,int len)
{
struct sockaddr_in ipaddr;
if(INVALID_SOCKET==sk)
{
WSADATA wsadata;
WSAStartup(MAKEWORD(2,0),&wsadata);
ipaddr.sin_family=AF_INET;
ipaddr.sin_port=htons(11000);
ipaddr.sin_addr.s_addr=inet_addr("169.254.2.2");
sk=socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP);
connect(sk,(sockaddr*)&ipaddr,sizeof(ipaddr));
}
try
{
if(SOCKET_ERROR==send(sk,buf,len,0))
throw SOCKET_ERROR;
}
catch (int j)
{
WSACleanup();
sk=INVALID_SOCKET;
}
// closesocket(sk);
}
|
|