1 | |
2 | //////////////////////////////////////////////////////////// |
3 | // Headers |
4 | //////////////////////////////////////////////////////////// |
5 | #include <iostream> |
6 | #include <cstdlib> |
7 | |
8 | |
9 | void runTcpServer(unsigned short port); |
10 | void runTcpClient(unsigned short port); |
11 | void runUdpServer(unsigned short port); |
12 | void runUdpClient(unsigned short port); |
13 | |
14 | |
15 | //////////////////////////////////////////////////////////// |
16 | /// Entry point of application |
17 | /// |
18 | /// \return Application exit code |
19 | /// |
20 | //////////////////////////////////////////////////////////// |
21 | int main() |
22 | { |
23 | // Choose an arbitrary port for opening sockets |
24 | const unsigned short port = 50001; |
25 | |
26 | // TCP, UDP or connected UDP ? |
27 | char protocol; |
28 | std::cout << "Do you want to use TCP (t) or UDP (u)? " ; |
29 | std::cin >> protocol; |
30 | |
31 | // Client or server ? |
32 | char who; |
33 | std::cout << "Do you want to be a server (s) or a client (c)? " ; |
34 | std::cin >> who; |
35 | |
36 | if (protocol == 't') |
37 | { |
38 | // Test the TCP protocol |
39 | if (who == 's') |
40 | runTcpServer(port); |
41 | else |
42 | runTcpClient(port); |
43 | } |
44 | else |
45 | { |
46 | // Test the unconnected UDP protocol |
47 | if (who == 's') |
48 | runUdpServer(port); |
49 | else |
50 | runUdpClient(port); |
51 | } |
52 | |
53 | // Wait until the user presses 'enter' key |
54 | std::cout << "Press enter to exit..." << std::endl; |
55 | std::cin.ignore(10000, '\n'); |
56 | std::cin.ignore(10000, '\n'); |
57 | |
58 | return EXIT_SUCCESS; |
59 | } |
60 | |