Hi
My problem is quite simple but I haven't found answers on other topics.
I'm trying to connect 2 computers (on different networks) using the public IP of the host :
int main()
{
std::cout << "Will you host? (y/n)" << endl;
char answer;
std::cin >> answer;
if (answer == 'y')
{
// Server side.
sf::IpAddress ip = sf::IpAddress::getPublicAddress(sf::seconds(3));
cout << "Server address : " << ip << endl; // Displays "176.182.85.44" (dummy).
sf::TcpListener listener;
if (listener.listen(53000) != sf::Socket::Done)
{
cout << "Error listening port 53000" << endl;
return 1;
}
cout << "Waiting for clients..." << endl;
sf::TcpSocket client;
if (listener.accept(client) != sf::Socket::Done)
{
cout << "Client not accepted" << endl;
return 1;
}
cout << client.getRemoteAddress() << " connected" << endl;
}
else
{
// Client side.
sf::TcpSocket server;
std::cout << "Connection to the server..." << endl;
sf::TcpSocket::Status status = server.connect("176.182.85.44", 53000, sf::seconds(3)); // Always returns sf::Socket::Error.
if (status != sf::Socket::Done)
{
std::cout << "Connection failed" << endl;
server.disconnect();
return 1;
}
std::cout << "Connection to " << server.getRemoteAddress() << " succeed" << endl;
}
return 0;
}
If I run this code on my local network (using 192.168.*.* or 127.0.0.1), it works perfectly.
But impossible to connect 2 computers over the network, even when I turn off the firewall on both sides !
Indeed, on the client I always get a "Connection failed" (server.connect() always returns sf::Socket::Error).
On the server side no connection is detected, it sticks to "Waiting for clients..."
I don't know if it is ISP related or anything else. Maybe somebody could help me? Thanks a lot