わかりました、これはトリッキーに思えます。IPC を実行するために QLocalServer を実装しました。しかし、それは正しく動作しません。クライアントが接続し、接続されていることを伝えます。サーバー...まあ...そうではありません。これにより、メッセージを受信できなくなります。
サーバーの実装は次のようになります。
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