for (i = 0; i < SENDTIMES; ++i)
{
printf("Send %d messages.\n", i + 1);
start = clock();
again2:
if ((sendto(sockfd, "A message!", 20, 0,
(struct sockaddr*)&serv, sizeof(serv))) < 0)
{
if (errno == EINTR)
goto again2;
perror("sendto");
exit(EXIT_FAILURE);
}
again3:
if ((recvfrom(sockfd, buf, BUFLEN, 0,
NULL, NULL)) < 0)
{
if (errno == EINTR)
goto again3;
perror("recvfrom");
exit(EXIT_FAILURE);
}
finish = clock();
duration = finish - start;
printf("Spend time: %fms\n", duration / CLOCKS_PER_SEC * 1000);
total += duration;
}
printf("\nAverage time: %fms\n", total / SENDTIMES / CLOCKS_PER_SEC * 1000);
return 0;
}