0

我有一个关于 QT QTcpServer server->listen(QHostAddress, qint16) 的问题。我的地址有问题。

我尝试使用 QHostAddress("127.0.0.1"),并且成功了。我尝试使用 QHostAddress::Any,但失败了(错误 10,不支持)。我尝试使用 QHostAddress::AnyIPv4,但失败了(同样的错误)。我尝试使用 QHostAddress("0.0.0.0"),但失败了,出现同样的错误。我尝试了接口的地址,它有效。

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."; 
    } 
}

似乎不可能让 QTcpServer 监听所有接口。操作系统是 Linux XUbuntu。如何让服务器监听所有接口?

4

0 回答 0