Important: Please read the Qt Code of Conduct -

Why am I getting a public IP on mobile and local IP on desktop?

  • I have this code here that sends a single character to the first CompRoomsBlinds it finds on the network on port 12000:

    MainWindow::MainWindow(QWidget *parent) :
        ui(new Ui::MainWindow)
        connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(shadeToggleClicked()));
        tcpSocket = new QTcpSocket(this);
        QHostInfo::lookupHost("CompRoomBlinds", this, SLOT(hostInfoResults(QHostInfo)));
    void MainWindow::shadeToggleClicked()
        tcpSocket->connectToHost(address, 12000);
        char test = 'R';
        tcpSocket->write(&test, 1);
    void MainWindow::hostInfoResults(QHostInfo info)
        address = info.addresses().first();

    When I run this code on my desktop the address is the local ip of the device I want to connect to. When I run it on mobile I get the public ip? Everything is on the same network. I guess the only difference would be that my desktop is plugged in via ethernet and my phone over wifi. So why are there different results?
    The server only operates over LAN so I need the local ip for it to work.

    Also note I verified the local ip works from my phone by putting it in as a literal string but the local ip could change so I need to find it by name.

  • I expect hostInfoResults is returning a public interface. Probably just luck PC works, maybe it lists local interfaces first?

    These might help:

Log in to reply