-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnao_iperfer.cpp
69 lines (63 loc) · 1.56 KB
/
nao_iperfer.cpp
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
62
63
64
65
66
67
68
69
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <unistd.h>
#include "client.h"
#include "server.h"
using namespace std;
int main(int argc, char *argv[])
{
if(argc<4)
{
cout<<"Error: missing or additional arguments"<<endl;
return 1;
}
string mode=argv[1];
string serverIP="";
int port=0;
int time=0;
if(!((mode=="-c" && argc==8)||(mode=="-s" && argc==4)))
{
cout<<"Error: missing or additional arguments"<<endl;
return 1;
}
int argCount=2;
string prefix="";
while(argCount<argc)
{
prefix=argv[argCount];
if(prefix[0]!='-'){
argCount++;
continue;
}
if(prefix=="-h") serverIP=argv[argCount+1];
else if(prefix=="-p") port=atoi(argv[argCount+1]);
else if(prefix=="-t") time=atoi(argv[argCount+1]);
argCount++;
}
if(port<1024 || port>65535)
{
cout<<"Error: port number must be in the range 1024 to 65535"<<endl;
return 1;
}
if(mode=="-c"){
client c(serverIP, port, time);
if(c.StartSend()==1)
c.PrintResult();
else
cout<<"Failed to send data."<<endl;
c.Close();
}
else if(mode=="-s"){
server s(port);
if(s.StartRecv()==1)
s.PrintResult();
else
cout<<"Failed to receive data."<<endl;
s.Close();
}
}