我有一个UDP服务器套接字,可以从客户端接收数据报,但无法将回复发送回任何一个。
这是我用来发送缓冲区的代码:
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()
返回-1,GetLastError()
表示10049,表示地址不可用。我在localhost
上发送和接收缓冲区。