Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Alkanor

Pages: [1]
1
Network / Re: Cannot connect to a remote IP with TCP
« on: April 17, 2018, 09:28:37 am »
Thank you for the reply.

I've read the FAQ but I don't understand a lot what I have to do about port forwarding.
If my server is behind a NAT (which is currently the case), have I to port forwarding the server by reaching it with UDP packets from the client?

2
Network / Cannot connect to a remote IP with TCP
« on: April 16, 2018, 12:58:34 pm »
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 ;D

Pages: [1]