QLocalServer IPC客户端工作,服务器没有

时间:2013-08-22 09:03:48

标签: c++ qt ipc qlocalsocket

好吧,这个看起来很棘手。我实现了一个QLocalServer来做一些IPC。但它不会正常工作。客户端连接并告诉我他已连接。服务器......好吧......不,这让我无法收到任何消息。

服务器实现如下所示:

PipeServer::PipeServer(QString servername, QObject *parent) : QObject(parent) {
    m_server = new QLocalServer(this);
    m_server->setSocketOptions(QLocalServer::WorldAccessOption);

    if (!m_server->listen(servername)) {
        logToFile("Unable to start the Server");
    } else {
        logToFile("Server up and running");
    }

    connect(m_server, SIGNAL(newConnection()), this, SLOT(socket_new_connection()));
}

void PipeServer::socket_new_connection() {

    logToFile("incoming connection");

    /* handling of connection ... */

}

输出服务器:

[Debug]: Server up and running

输出客户端:

[Debug]: ConnectingState 
[Debug]: ConnectedState 
[Debug]: socket_connected 

没有正在运行的服务器的输出客户端:

[Debug]: ConnectingState 
[Debug]: UnconnectedState 
[Debug]: socket_error 
[Debug]: ServerNotFoundError 
如果在连接客户端时关闭服务器,则

客户端输出:

[Debug]: ClosingState 
[Debug]: UnconnectedState 
[Debug]: socket_disconnected 

所以客户端肯定是连接到服务器,但从不调用服务器的newConnection()信号。我甚至尝试用m_server->hasPendingConnections()来检查自己的连接......但是这也会返回false ...

[编辑]

我每隔30秒检查服务器状态:

void PipeServer::checkListening(){

if(m_server->isListening()){
    logToFile("server is listening");
} else {
    logToFile("server is NOT listening");
}

if(m_server->hasPendingConnections()){
    logToFile("server has pending connections");
} else {
    logToFile("server has no pending connections");
}

}

输出:

[Debug]: server is listening
[Debug]: server has no pending connections

0 个答案:

没有答案