Added the trunk/branches/tags directories at repository root, and moved previous root into trunk/
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1002 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
commit
2f524481c1
974 changed files with 295448 additions and 0 deletions
62
samples/sockets/Sockets.cpp
Normal file
62
samples/sockets/Sockets.cpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <iostream>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Function prototypes
|
||||
// (I'm too lazy to put them into separate headers...)
|
||||
////////////////////////////////////////////////////////////
|
||||
void DoClientTCP(unsigned short Port);
|
||||
void DoClientUDP(unsigned short Port);
|
||||
void DoServerTCP(unsigned short Port);
|
||||
void DoServerUDP(unsigned short Port);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Application exit code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
// Choose a random port for opening sockets (ports < 1024 are reserved)
|
||||
const unsigned short Port = 2435;
|
||||
|
||||
// TCP or UDP ?
|
||||
char Protocol;
|
||||
std::cout << "Do you want to use TCP ('t') or UDP ('u') ? ";
|
||||
std::cin >> Protocol;
|
||||
|
||||
// Client or server ?
|
||||
char Who;
|
||||
std::cout << "Do you want to be a server ('s') or a client ('c') ? ";
|
||||
std::cin >> Who;
|
||||
|
||||
if (Who == 's')
|
||||
{
|
||||
// Run as a server
|
||||
if (Protocol == 't')
|
||||
DoServerTCP(Port);
|
||||
else
|
||||
DoServerUDP(Port);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Run as a client
|
||||
if (Protocol == 't')
|
||||
DoClientTCP(Port);
|
||||
else
|
||||
DoClientUDP(Port);
|
||||
}
|
||||
|
||||
// Wait until the user presses 'enter' key
|
||||
std::cout << "Press enter to exit..." << std::endl;
|
||||
std::cin.ignore(10000, '\n');
|
||||
std::cin.ignore(10000, '\n');
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue