0

i have a question about QT QTcpServer server->listen(QHostAddress, qint16). I have problems with the address.

I tried with QHostAddress("127.0.0.1"), and that worked. I tried with QHostAddress::Any, and that failed (error 10, not supported). I tried with QHostAddress::AnyIPv4, and that failed (same error). I tried with QHostAddress("0.0.0.0"), and that failed, with same error. I tried with the address of the interface, that worked.

NotificationServer::NotificationServer(QObject *parent) : QObject(parent) {     
    server = new QTcpServer(this); 
    connect(server, SIGNAL(newConnection()), this, SLOT(newConnection())); 
    if (!server->listen(QHostAddress::Any, port)) { 
        qDebug() << "Server could not start." << server->serverError(); 
        server = nullptr; 
    } else { 
        qDebug() << "Server started."; 
    } 
}

It seems, that it is not possible making the QTcpServer listen on all interfaces. OS is Linux XUbuntu. How can i make the server listen at all interfaces?

Onur Tuna
  • 1,030
  • 1
  • 10
  • 28
Siegfried
  • 31
  • 5
  • QHostAddress::Any should work. Which version of Qt do you use? Can you provide a proper implementation of your code? – Onur Tuna Mar 13 '18 at 10:19
  • The version is some 5.something. NotificationServer::NotificationServer(QObject *parent) : QObject(parent) { server = new QTcpServer(this); connect(server, SIGNAL(newConnection()), this, SLOT(newConnection())); if (!server->listen(QHostAddress::Any, port)) { qDebug() << "Server could not start." << server->serverError(); server = nullptr; } else { qDebug() << "Server started."; } } – Siegfried Mar 13 '18 at 10:40
  • Sorry, how to format code? – Siegfried Mar 13 '18 at 10:46
  • BTW, if that matters: The XUbuntu is running in a VMWare virtual machine, running on Windows – Siegfried Mar 13 '18 at 10:55
  • When you write something like `server->listen(QHostAddress("10.10.0.10"), port)`, here 10.10.0.10 is an example of an interface ip, it works right? – Onur Tuna Mar 13 '18 at 12:41
  • Yes. Any valid IPv4 address works, except 0.0.0.0 ("valid" means existing interface :) ) – Siegfried Mar 13 '18 at 12:53
  • How did you configure `VMWare` _network options_? **Nat** or **Bridged** ? – Mohammad Kanan Mar 13 '18 at 17:19
  • First: NAT. Second: Named Network (VM Network) – Siegfried Mar 14 '18 at 06:02

0 Answers0