I have a UDP server socket which can receive datagrams from clients, but is not able to send a reply back to any of them.
This is the code I use to send the buffer:
SOCKADDR_IN addr;
memset((char*)&addr, 0, sizeof(addr));
const char* ip = "127.0.0.1";
u_short port = 8888 // IP of the client to which the buffer is going to
if (inet_pton(AF_INET, ip, &addr) == 1)
{
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
sendto(s, buffer, UDP_PACKET_SIZE, NULL, (SOCKADDR *)&addr, addrlen);
}
sendto()
returns -1 and GetLastError()
says 10049 which means the address is not available. I'm sending and receiving the buffer on localhost
.