Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Why am I getting a public IP on mobile and local IP on desktop?
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 2 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andaharoo
    wrote on last edited by
    #1

    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) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        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);
        tcpSocket->disconnectFromHost();
    }
    
    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.

    1 Reply Last reply
    0
    • 6thC6 Offline
      6thC6 Offline
      6thC
      wrote on last edited by
      #2

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

      These might help:
      http://doc.qt.io/qt-5/qhostaddress.html#SpecialAddress-enum
      http://doc.qt.io/qt-5/qtnetwork-fortuneserver-example.html

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved