Added support for the CMake build system
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1550 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
aa612ec63a
commit
a991fe8e4d
144 changed files with 2086 additions and 7033 deletions
59
examples/sockets/Sockets.cpp
Normal file
59
examples/sockets/Sockets.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
void RunTcpServer(unsigned short Port);
|
||||
void RunTcpClient(unsigned short Port);
|
||||
void RunUdpServer(unsigned short Port);
|
||||
void RunUdpClient(unsigned short Port);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Entry point of application
|
||||
///
|
||||
/// \return Application exit code
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int main()
|
||||
{
|
||||
// Choose an arbitrary port for opening sockets
|
||||
const unsigned short port = 50001;
|
||||
|
||||
// TCP, UDP or connected 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 (protocol == 't')
|
||||
{
|
||||
// Test the TCP protocol
|
||||
if (who == 's')
|
||||
RunTcpServer(port);
|
||||
else
|
||||
RunTcpClient(port);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Test the unconnected UDP protocol
|
||||
if (who == 's')
|
||||
RunUdpServer(port);
|
||||
else
|
||||
RunUdpClient(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