2

okay this one seems tricky. I implemented a QLocalServer to do some IPC. But it won't work properly. The client connects and tells me he is connected. the server...well...not, which makes me unable to recieve any messages.

the server implementation looks like this:

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 ... */

}

output server:

[Debug]: Server up and running

output client:

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

output client with no running server:

[Debug]: ConnectingState 
[Debug]: UnconnectedState 
[Debug]: socket_error 
[Debug]: ServerNotFoundError 

client output if i close the server while the client is connected:

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

so the client is definitely connecting to the server, but the server's newConnection() signal is never called. i even tried to check the connection myself with m_server->hasPendingConnections() ...but that returns false, too...

[edit]

i check the server status every 30 seconds:

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

}

which outputs:

[Debug]: server is listening
[Debug]: server has no pending connections
Mr.Manhattan
  • 5,315
  • 3
  • 22
  • 34
  • From the code you've posted, it looks ok, though personally, I'd make the connection to newConnection() before calling listen(). Could you have forgotten to include the Q_OBJECT macro in the definition of the PipeServer class? Also, when the connect call is made, does it return a valid object, or NULL? – TheDarkKnight Aug 22 '13 at 09:23
  • connection doesn't return NULL, and i put the connect function over the listen function, still same results – Mr.Manhattan Aug 22 '13 at 09:27
  • Is there any error message in the debug output window when running over the connect call? – TheDarkKnight Aug 22 '13 at 09:46
  • No. but even if the connect call wouldn'twork, i check every 30 seconds if the server has pending connections, which would show a pending connection if the socket_new_connection() method didn't run... – Mr.Manhattan Aug 22 '13 at 09:57
  • 1
    Just to test, if you use the function waitForNewConnection, does that receive it? – TheDarkKnight Aug 22 '13 at 09:58
  • well, that actually works, tough i still can't recieve anything....but i'll work that out... – Mr.Manhattan Aug 22 '13 at 10:19
  • If that works, then the problem is likely to be with the signal / slots. Try deleting the moc files and running qmake. – TheDarkKnight Aug 22 '13 at 10:40
  • I think it might be the problem that i run the server in a plain QObject, not a QThread, since there is no event queue running – Mr.Manhattan Aug 22 '13 at 10:55
  • Please override "QLocalServer::incomingConnection(quintptr socketDescriptor)" in PipeServer. Check, whether it gets called or not . this is for narrow down the issue. – Ashif Aug 22 '13 at 10:58
  • PipeServer is just a manager, not a inheriting class – Mr.Manhattan Aug 22 '13 at 11:00
  • If you've no QApplication and event queue running, then yes, that would prevent the calling of your socket. – TheDarkKnight Aug 22 '13 at 11:01

0 Answers0