Results 1 to 3 of 3

Thread: Multiple socket notifiers for same socket

  1. #1
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Question Multiple socket notifiers for same socket

    Hello,

    I am currently working an a server/client application using SSL/TCP.
    In order do archive this, i do the following:

    1. create a QTcpServer
    2. make it listen to any host address and a specific port
    3. connect the "newConnection()" SIGNAL to my "newTcpConnection()" SLOT
    4. There i use the socketDescriptor of the nextPendingConnection and set it to a new sslSocket

    The code looks like this:

    Qt Code:
    1. void sslServer::newTcpConnection()
    2. {
    3. qDebug() << "New TCP connection";
    4. qintptr descriptor = tcpServer->nextPendingConnection()->socketDescriptor();
    5.  
    6. QSslSocket *sslSocket = new QSslSocket(this);
    7. if (!sslSocket->setSocketDescriptor(descriptor)) { //<--Displays mentioned error
    8. qCritical() << "Setting socket descriptor failed";
    9. emit error(sslSocket->errorString());
    10. delete sslSocket;
    11. return;
    12. }
    13. ...
    14. }
    To copy to clipboard, switch view to plain text mode 

    But i do not understand why I get the following warning:

    "QSocketNotifier: Multiple socket notifiers for the same socket 520 and type Read"

    The warning occurs when executing the marked line.
    I do not use threads and i create a new socket for every new connection,
    therefore it should only be one socket notifier per sslSocket.


    I would appreciate any help.

    Thank you!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Multiple socket notifiers for same socket

    nextPendingConnection() is a convenience wrapper that results in a fully set up QTcpSocket.

    For SSL, or any other special setup needs, the correct way is to derive from QTcpServer and overwrite incomingConnection().
    That method gets the socket descriptor and allows you to set up a QSslSocket instead of a QTcpSocket.

    Cheers,
    _

  3. #3
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: Multiple socket notifiers for same socket

    Thank you so much!

    I completely missed that, tryed it right now and works as you described

Similar Threads

  1. Same socket in multiple classes
    By kupikupi in forum Newbie
    Replies: 5
    Last Post: 19th January 2014, 17:26
  2. Replies: 2
    Last Post: 22nd May 2011, 22:31
  3. Replies: 0
    Last Post: 5th November 2009, 04:11
  4. socket notifiers cannot be enabled from another thread
    By babu198649 in forum Qt Programming
    Replies: 5
    Last Post: 4th April 2009, 16:15
  5. Replies: 10
    Last Post: 20th March 2007, 23:19

Tags for this Thread

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.