terminado
[MHWsCURYlr.git] / tcp / sort / client.c
blob1f4d4fe8412eeb8637794a1f6041960b07cd59c5
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <assert.h>
5 #include <time.h>
6 #include <sys/socket.h>
7 #include <arpa/inet.h>
8 #include <unistd.h>
10 int main(int argc, char **argv)
12 int i, mySocket;
13 struct sockaddr_in server;
14 double beginTime, endTime;
15 int vetor[VECTOR_SIZE], vetorResposta[VECTOR_SIZE];
16 int vectorSize = VECTOR_SIZE * sizeof(int);
18 if(argc < 3) {
19 printf("Usage: %s <address> <port>\n", argv[0]);
20 exit(1);
23 memset(&server, 0, sizeof(server));
24 server.sin_family = AF_INET;
25 server.sin_addr.s_addr = inet_addr(argv[1]);
26 server.sin_port = htons(atoi(argv[2]));
28 for(i = 0; i < VECTOR_SIZE; i++)
29 vetor[i] = i;
31 beginTime = clock();
32 for(i = 0; i < TESTS_TOTAL; i++) {
33 #ifdef DEBUG
34 printf("client: %i\n", i);
35 #endif
37 mySocket = socket(AF_INET, SOCK_STREAM, 0);
38 assert(mySocket != -1);
39 assert(connect(mySocket, (struct sockaddr *) &server, sizeof(server)) == 0);
41 #ifdef DEBUG
42 int j;
43 for(j = 0; j < VECTOR_SIZE; j++)
44 printf("%i ", vetor[j]);
45 printf("\n");
46 #endif
47 assert(send(mySocket, vetor, vectorSize, 0) == vectorSize);
48 assert(recv(mySocket, vetorResposta, vectorSize, 0) == vectorSize);
49 //assert(send(mySocket, NULL, 0, 0) == 0);
50 //assert(recv(mySocket, NULL, 0, 0) == 0);
52 close(mySocket);
53 #ifdef DEBUG
54 for(j = 0; j < VECTOR_SIZE; j++)
55 printf("%i ", vetorResposta[j]);
56 printf("\n");
57 #endif
59 endTime = clock();
61 printf("%g\n", ((endTime - beginTime) / (double) (TESTS_TOTAL)) * (1000000 / (double) CLOCKS_PER_SEC));
63 return 0;