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

Author Topic: TCP doesn't work on remote computer  (Read 9043 times)

0 Members and 1 Guest are viewing this topic.

The_Xlebushek

  • Newbie
  • *
  • Posts: 4
    • View Profile
TCP doesn't work on remote computer
« on: June 11, 2021, 09:19:43 pm »
I created a simple application that sends a string to another machine. It works fine with both the client and the server connected to the same network, but it doesn't connect to a public address. Wireshark shows that the server is not responding if I send a request to the remote computer.

#include <SFML\Network.hpp>
#include <iostream>

int main()
{
        sf::Packet packet;
        char who;
        std::cout << "Are you a server (s) or a client (c)?" << std::endl;
        std::cin >> who;
        if (who == 's')
        {
                sf::TcpSocket client;
                std::cout << "Public: " << sf::IpAddress::getPublicAddress() << std::endl;
                std::cout << "Local: " << sf::IpAddress::getLocalAddress() << std::endl;
                sf::TcpListener listener;
                if (listener.listen(3005) != sf::Socket::Done)
                        std::cout << "Could not bind port" << std::endl;
                if (listener.accept(client) != sf::Socket::Done)
                        std::cout << "Could not connect to client" << std::endl;
                client.receive(packet);
                std::string name;
                packet >> name;
                std::cout << name << std::endl;
        }
        else if (who == 'c')
        {
                sf::TcpSocket server;
                sf::IpAddress ip;
                std::cin >> ip;
                if (server.connect(ip, 3005) != sf::Socket::Done)
                        std::cout << "Could not connect to server" << std::endl;
                packet << "Some random text";
                server.send(packet);
                std::cout << "Packet was sent" << std::endl;
        }
        system("pause");
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: TCP doesn't work on remote computer
« Reply #1 on: June 14, 2021, 09:26:30 am »
Connecting across the internet (or different local networks) requires some knowledge in networking to properly analyze what's happening.

The FAQ has a good list of things to check: https://www.sfml-dev.org/faq.php#network-internet-network
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/