-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_upd.cpp
More file actions
61 lines (51 loc) · 1.66 KB
/
client_upd.cpp
File metadata and controls
61 lines (51 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "common.h"
using namespace std;
using namespace std::chrono;
int main(int argc, char *argv[])
{
if(argc < 4)
{
cout << "Expected execution : ./client host port packetSize" << endl;
return 0;
}
int sckt,bufferSize = atoi(argv[3]);
char message[bufferSize];
char buffer[bufferSize];
uint i;
string inputString;
struct hostent *remoteHost;
struct sockaddr_in server_addr;
socklen_t size = sizeof(server_addr);
int count = 0;
sckt = socket(AF_INET, SOCK_DGRAM, 0);
double throughPut,duration;
if (sckt < 0)
{
perror("Error establishing a socket !!");
return 0;
}
remoteHost = gethostbyname(argv[1]);
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(atoi(argv[2]));
bcopy((char *)remoteHost->h_addr,(char *)&server_addr.sin_addr,remoteHost->h_length);
high_resolution_clock::time_point t1 = high_resolution_clock::now();
while(count < 30)
{
memset(buffer,0,strlen(buffer));
memset(message,0,strlen(message));
inputString = "Packet " + to_string(count);
for(i=0;i<inputString.size();i++){
message[i]=inputString[i];
}
sendto(sckt,message,bufferSize,0,(struct sockaddr *) &server_addr, size);
recvfrom(sckt,buffer,bufferSize,0,(struct sockaddr *) &server_addr, &size);
cout <<"Server : "<< buffer << endl;
count++;
}
high_resolution_clock::time_point t2 = high_resolution_clock::now();
duration = duration_cast<microseconds>( t2 - t1 ).count();
throughPut = (30000*bufferSize)/duration;
cout << "ThroughPut for the execution : " << throughPut << endl;
close(sckt);
return 0;
}