Kake_Fisk
Kake_Fisk

Reputation: 1165

Get the host IP address in SFML

I'm making a game where a player can host an online session. I'm using SFML network library. But I want to display the IP address of the server host when it is waiting for incoming connections. How can I get this IP address? I'm looking for the internal IP address, but if it's possible to get the external IP address, that would be a bonus.

sf::TcpListener listener;

// bind the listener to a port
if (listener.listen(53000) != sf::Socket::Done)
{
    // error...
}

// accept a new connection
sf::TcpSocket client;
if (listener.accept(client) != sf::Socket::Done)
{
    // error...
}

Upvotes: 1

Views: 1364

Answers (1)

Hiura
Hiura

Reputation: 3530

Unless I've misunderstood your problem, you're looking for those static functions:

sf::IpAddress sf::IpAddress::getLocalAddress();
sf::IpAddress sf::IpAddress::getPublicAddress(Time timeout);

Documentation is here.

Upvotes: 3

Related Questions