Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Local client socket not emitting error when server not running
Forum Updated to NodeBB v4.3 + New Features

Local client socket not emitting error when server not running

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nitks.abhinav
    wrote on last edited by
    #1

    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();
        }
    }
    
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      have you tried connecting to the disconnected() signal?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nitks.abhinav
        wrote on last edited by
        #3

        Yes , that also does not work, I think disconnected() works when connection is disconnected at run time after successful connection.

        S 1 Reply Last reply
        0
        • N nitks.abhinav

          Yes , that also does not work, I think disconnected() works when connection is disconnected at run time after successful connection.

          S Offline
          S Offline
          Stoyan
          wrote on last edited by
          #4

          @nitks.abhinav
          Try to put "connect(socket" lines before this one:

          socket->connectToServer("/usr/bin/fortune");
          
          1 Reply Last reply
          0
          • N Offline
            N Offline
            nitks.abhinav
            wrote on last edited by
            #5

            Yes it worked, but its strange it should be dynamic. Anyways, Thanks.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved