1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
//Get AddressInfo
addrinfo hints, *p;
ZeroMemory(&hints,sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM;
rc = getaddrinfo(szHost,szPort,&hints,&g_pAddr);
if(rc)
cout << "Error3\n";
char nodebuffer[100];
char servicebuffer[100];
rc = getnameinfo(g_pAddr->ai_addr,sizeof(sockaddr),nodebuffer,100,servicebuffer,100,0);
cout << nodebuffer << ":" << servicebuffer << endl;
rc = WSAGetLastError();
cout << "Last WSA Error: " << rc << endl;
p = g_pAddr;
char buffer[220];
strcpy_s(buffer,"Test Message");
rc = sendto(g_Socket,buffer,200,0,p->ai_addr, p->ai_addrlen);
cout << "Bytes sent: " << rc << endl;
rc = WSAGetLastError();
cout << "Last WSA Error: " << rc << endl;
|