-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapplication.cpp
More file actions
38 lines (32 loc) · 973 Bytes
/
Copy pathapplication.cpp
File metadata and controls
38 lines (32 loc) · 973 Bytes
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
#include "server.h"
#include "client.h"
using namespace std;
void printUsage(int argc, char* argv[]) {
printf("Usage: ./%s <program type> <port> \n", argv[0]);
printf("<program type>: 's' for server and 'c' for client \n");
printf("<port>: listening port of server/client \n");
}
int main(int argc, char **argv ) {
int port = atoi(argv[2]);
// check the parameters passed to this program
if(argc != 3) {
printUsage(argc, argv);
return -1;
}
// check if it client or server
if(strcmp("s", argv[1]) == 0 && port > 1024) {
// server initalization
Server lServer(port);
}
else if(strcmp("c", argv[1]) == 0 && port > 1024) {
// execute client code
Client lClient(port);
}
else {
printUsage(argc, argv);
return -1;
}
// also do a valid port number check
// check the program type and based on it initalize corresponding objects
return 0;
}