2012-04-20 1 views

答えて

0

簡単なエコークライアント・サーバを作成し、それはあなたがbindsocketlistenacceptreadwriteが必要になります

機能を返信するsendからかかった時間を測定します。すべてのドキュメントはmanページ(2)にあります。

int sock = socket(AF_INET, SOCK_STREAM, 0); 
char buf[1024]; 
struct sockadd_in host; 
/* ... set up params ... */ 
int connfd = connect(sock, &host) 

time_t now = time(NULL); 
time_t then = 0; 
time_t delta_t = 0; 
write(connfd, "hi", strlen("hi")); 
read(connfd, buf,1024); 
then = time(NULL); 

delta_t = then - now; 

これは、それがどのように見えるべきかの並べ替え(ラフ擬似/ Cコード)

です