Improved the API documentation of sf::IpAddress
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1452 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
b7eb09cb79
commit
e924c9cf39
34 changed files with 336 additions and 264 deletions
|
@ -10,28 +10,28 @@
|
|||
/// Create a client and send a message to a running server
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void DoClientUDP(unsigned short Port)
|
||||
void DoClientUDP(unsigned short port)
|
||||
{
|
||||
// Ask for server address
|
||||
sf::IPAddress ServerAddress;
|
||||
sf::IpAddress serverAddress;
|
||||
do
|
||||
{
|
||||
std::cout << "Type address or name of the server to send the message to : ";
|
||||
std::cin >> ServerAddress;
|
||||
std::cin >> serverAddress;
|
||||
}
|
||||
while (!ServerAddress.IsValid());
|
||||
while (!serverAddress.IsValid());
|
||||
|
||||
// Create a UDP socket for communicating with server
|
||||
sf::SocketUDP Client;
|
||||
sf::SocketUDP client;
|
||||
|
||||
// Send a message to the server
|
||||
char Message[] = "Hi, I'm a client !";
|
||||
if (Client.Send(Message, sizeof(Message), ServerAddress, Port) != sf::Socket::Done)
|
||||
char message[] = "Hi, I'm a client !";
|
||||
if (client.Send(message, sizeof(message), serverAddress, port) != sf::Socket::Done)
|
||||
return;
|
||||
std::cout << "Message sent to server : \"" << Message << "\"" << std::endl;
|
||||
std::cout << "Message sent to server : \"" << message << "\"" << std::endl;
|
||||
|
||||
// Close the socket when we're done
|
||||
Client.Close();
|
||||
client.Close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -39,27 +39,27 @@ void DoClientUDP(unsigned short Port)
|
|||
/// Launch a server and wait for incoming messages
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void DoServerUDP(unsigned short Port)
|
||||
void DoServerUDP(unsigned short port)
|
||||
{
|
||||
// Create a UDP socket for communicating with clients
|
||||
sf::SocketUDP Server;
|
||||
sf::SocketUDP server;
|
||||
|
||||
// Bind it to the specified port
|
||||
if (!Server.Bind(Port))
|
||||
if (!server.Bind(port))
|
||||
return;
|
||||
|
||||
// Receive a message from anyone
|
||||
sf::IPAddress ClientAddress;
|
||||
unsigned short ClientPort;
|
||||
char Message[128];
|
||||
std::size_t Received;
|
||||
if (Server.Receive(Message, sizeof(Message), Received, ClientAddress, ClientPort) != sf::Socket::Done)
|
||||
sf::IpAddress clientAddress;
|
||||
unsigned short clientPort;
|
||||
char message[128];
|
||||
std::size_t received;
|
||||
if (server.Receive(message, sizeof(message), received, clientAddress, clientPort) != sf::Socket::Done)
|
||||
return;
|
||||
|
||||
// Display it
|
||||
std::cout << "Message received from " << ClientAddress << " on port " << ClientPort
|
||||
<< ": \"" << Message << "\"" << std::endl;
|
||||
std::cout << "Message received from " << clientAddress << " on port " << clientPort
|
||||
<< ": \"" << message << "\"" << std::endl;
|
||||
|
||||
// Close the socket when we're done
|
||||
Server.Close();
|
||||
server.Close();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue