Client program to send a number to server and check whether it is prime or not. client calculates time taken .
#include<arpa/inet.h>
#include<sys/time.h>
//#include "unp.h"
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
main(int argc,char *argv[])
{
int
sock,ret,z,x,n;
struct
sockaddr_in obj;
struct timeval
tv2,tv1;
static char
str[30],str2[30];
char
*ptr,*ptr2;
char b[50];
int totalT;
obj.sin_family=AF_INET;
obj.sin_port=atoi(argv[1]);
obj.sin_addr.s_addr=inet_addr("172.16.6.79");//INADDR_ANY;
sock=socket(AF_INET,SOCK_DGRAM,0);
printf("eneter the number");
scanf("%d",&n);
gettimeofday(&tv1,NULL);
ret=sendto(sock,&n,sizeof(n),0,(struct
sockaddr*)&obj,sizeof(obj));
int
recv_count=0;
printf("\n the response form
sernver is");
ret=recvfrom(sock,b,sizeof(b),0,(struct sockaddr*)&obj,sizeof(obj));
recv_count++;
gettimeofday(&tv2,NULL);
totalT=(tv2.tv_sec-tv1.tv_sec)+(tv2.tv_usec-tv1.tv_usec);
printf("\n response %s",b);
printf("recv_count= %d and time taken=%ld microseconds
\n",recv_count,totalT);
close(sock);
}
No comments:
Post a Comment