Back to index

libsfml  1.6+dfsg2
Sockets.cpp
Go to the documentation of this file.
00001 
00003 // Headers
00005 #include <iostream>
00006 #include <cstdlib>
00007 
00008 
00010 // Function prototypes
00011 // (I'm too lazy to put them into separate headers...)
00013 void DoClientTCP(unsigned short Port);
00014 void DoClientUDP(unsigned short Port);
00015 void DoServerTCP(unsigned short Port);
00016 void DoServerUDP(unsigned short Port);
00017 
00018 
00025 int main()
00026 {
00027     // Choose a random port for opening sockets (ports < 1024 are reserved)
00028     const unsigned short Port = 2435;
00029 
00030     // TCP or UDP ?
00031     char Protocol;
00032     std::cout << "Do you want to use TCP ('t') or UDP ('u') ? ";
00033     std::cin  >> Protocol;
00034 
00035     // Client or server ?
00036     char Who;
00037     std::cout << "Do you want to be a server ('s') or a client ('c') ? ";
00038     std::cin  >> Who;
00039 
00040     if (Who == 's')
00041     {
00042         // Run as a server
00043         if (Protocol == 't')
00044             DoServerTCP(Port);
00045         else
00046             DoServerUDP(Port);
00047     }
00048     else
00049     {
00050         // Run as a client
00051         if (Protocol == 't')
00052             DoClientTCP(Port);
00053         else
00054             DoClientUDP(Port);
00055     }
00056 
00057     // Wait until the user presses 'enter' key
00058     std::cout << "Press enter to exit..." << std::endl;
00059     std::cin.ignore(10000, '\n');
00060     std::cin.ignore(10000, '\n');
00061 
00062     return EXIT_SUCCESS;
00063 }