这仅发送一次数据,这对我来说似乎是不合理的,因为它处于 for 循环中:
char* hello;
for (int i = 0; i < 10; i++) {
hello = "Hello world!\n";
if (UDT::ERROR == UDT::send(client, hello, strlen(hello) + 1, 0))
{
cout << "send: " << UDT::getlasterror().getErrorMessage();
}
}
它不应该发送数据10次吗?我不明白。这是整个程序(很短):
int main()
{
UDTSOCKET client;
sockaddr_in serv_addr;
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(9000);
inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr);
memset(&(serv_addr.sin_zero), '\0', 8);
client = UDT::socket(AF_INET, SOCK_STREAM, 0);
// connect to the server, implict bind
if (UDT::ERROR == UDT::connect(client, (sockaddr*)&serv_addr, sizeof(serv_addr)))
{
cout << "connect: " << UDT::getlasterror().getErrorMessage();
}
char* hello;
for (int i = 0; i < 10; i++) {
hello = "Hello world!\n";
if (UDT::ERROR == UDT::send(client, hello, strlen(hello) + 1, 0))
{
cout << "send: " << UDT::getlasterror().getErrorMessage();
}
}
UDT::close(client);
system("pause");
}