Results 1 to 2 of 2

Thread: Local client socket not emitting error when server not running

  1. #1
    Join Date
    Sep 2017
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: 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,

    Qt Code:
    1. void ClientThread::serverConnect()
    2. {
    3. //Connect to the local notification srever
    4. socket = new QLocalSocket(this);
    5. qDebug() << "Client thread: connecting to notification server\n";
    6. socket->connectToServer("/usr/bin/fortune");
    7. qDebug() << "Client thread: connected to server";
    8.  
    9. connect(socket, SIGNAL(readyRead()), this, SLOT(readMsg()), Qt::DirectConnection);
    10. connect(socket, SIGNAL(error(QLocalSocket::LocalSocketError)),
    11. this, SLOT(displayError(QLocalSocket::LocalSocketError)));
    12. }
    13.  
    14. void ClientThread::displayError(QLocalSocket::LocalSocketError socketError)
    15. {
    16.  
    17. switch (socketError) {
    18. case QLocalSocket::ServerNotFoundError:
    19. qDebug() << "Client thread: The host was not found. Please check the "
    20. "host name and port settings.";
    21.  
    22. break;
    23. case QLocalSocket::ConnectionRefusedError:
    24. qDebug() << "Client thread: The connection was refused by the peer. "
    25. "Make sure the fortune server is running, "
    26. "and check that the host name and port "
    27. "settings are correct.";
    28. break;
    29. case QLocalSocket::PeerClosedError:
    30. qDebug() << "Client thread: peer closed error.";
    31. break;
    32. default:
    33. qDebug() << "Client thread: The following error occurred: " << socket->errorString();
    34. }
    35. }
    To copy to clipboard, switch view to plain text mode 


    Added after 1 37 minutes:


    Got it resolved, had to put " socket->connectToServer("/usr/bin/fortune");" before connecting signal/slot.


    Thanks
    Last edited by nitks.abhinav; 27th October 2017 at 19:52.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Local client socket not emitting error when server not running

    Got it resolved, had to put " socket->connectToServer("/usr/bin/fortune");" before connecting signal/slot.
    You mean "after connecting signal / slot", don't you? If you try to connect to the server and it fails, the local socket will emit the error() signal, but unless you have connected your QLocalSocket instance's error() signal to a slot, you won't see the signal.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 4
    Last Post: 9th February 2017, 08:05
  2. Replies: 3
    Last Post: 16th August 2015, 12:32
  3. Replies: 1
    Last Post: 27th March 2009, 14:20
  4. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 11:22
  5. Programming client-server with socket in multi-languages
    By philiptine in forum Qt Programming
    Replies: 3
    Last Post: 7th September 2007, 08:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.