Solved Local client socket not emitting error when server not running
-
Hi,
I have a local client socket and it works fine i.e. connects to local (Unix domain) server , receives data.
But when server is not running it does not emit the error signal, below is the code.
Thanks,
void ClientThread::serverConnect() { //Connect to the local notification srever socket = new QLocalSocket(this); qDebug() << "Client thread: connecting to notification server\n"; socket->connectToServer("/usr/bin/fortune"); qDebug() << "Client thread: connected to server"; connect(socket, SIGNAL(readyRead()), this, SLOT(readMsg()), Qt::DirectConnection); connect(socket, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(displayError(QLocalSocket::LocalSocketError))); } void ClientThread::displayError(QLocalSocket::LocalSocketError socketError) { switch (socketError) { case QLocalSocket::ServerNotFoundError: qDebug() << "Client thread: The host was not found. Please check the " "host name and port settings."; break; case QLocalSocket::ConnectionRefusedError: qDebug() << "Client thread: The connection was refused by the peer. " "Make sure the fortune server is running, " "and check that the host name and port " "settings are correct."; break; case QLocalSocket::PeerClosedError: qDebug() << "Client thread: peer closed error."; break; default: qDebug() << "Client thread: The following error occurred: " << socket->errorString(); } }
-
have you tried connecting to the
disconnected()
signal? -
Yes , that also does not work, I think disconnected() works when connection is disconnected at run time after successful connection.
-
@nitks.abhinav
Try to put "connect(socket" lines before this one:socket->connectToServer("/usr/bin/fortune");
-
Yes it worked, but its strange it should be dynamic. Anyways, Thanks.