| 1 | |
| 2 | //////////////////////////////////////////////////////////// |
| 3 | // Headers |
| 4 | //////////////////////////////////////////////////////////// |
| 5 | #include <iomanip> |
| 6 | #include <iostream> |
| 7 | #include <cstdlib> |
| 8 | |
| 9 | |
| 10 | //////////////////////////////////////////////////////////// |
| 11 | // Function prototypes |
| 12 | // (I'm too lazy to put them into separate headers...) |
| 13 | //////////////////////////////////////////////////////////// |
| 14 | void doClient(unsigned short port); |
| 15 | void doServer(unsigned short port); |
| 16 | |
| 17 | |
| 18 | //////////////////////////////////////////////////////////// |
| 19 | /// Entry point of application |
| 20 | /// |
| 21 | /// \return Application exit code |
| 22 | /// |
| 23 | //////////////////////////////////////////////////////////// |
| 24 | int main() |
| 25 | { |
| 26 | // Choose a random port for opening sockets (ports < 1024 are reserved) |
| 27 | const unsigned short port = 2435; |
| 28 | |
| 29 | // Client or server ? |
| 30 | char who; |
| 31 | std::cout << "Do you want to be a server ('s') or a client ('c')? " ; |
| 32 | std::cin >> who; |
| 33 | |
| 34 | if (who == 's') |
| 35 | { |
| 36 | // Run as a server |
| 37 | doServer(port); |
| 38 | } |
| 39 | else |
| 40 | { |
| 41 | // Run as a client |
| 42 | doClient(port); |
| 43 | } |
| 44 | |
| 45 | // Wait until the user presses 'enter' key |
| 46 | std::cout << "Press enter to exit..." << std::endl; |
| 47 | std::cin.ignore(10000, '\n'); |
| 48 | |
| 49 | return EXIT_SUCCESS; |
| 50 | } |
| 51 | |