Network: QUdpSocket setSocketOption seems not work



  • Hi

    I have tryed to set different values for ttl option of an QUdpSocket to send multicast messages.
    But when I verify with Wireshark I allways see ttl=1

    setSocketOption is void function so I try step by step debugging and I found that setSocketOption fail :

    in "void QAbstractSocket::setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value)"

    • "if (QSslSocket sslSocket = qobject_cast<QSslSocket>(this))"
      is false
      so "sslSocket->setSocketOption" is not called

    • "if (!d_func()->socketEngine)"
      is true
      so it returns and "d_func()->socketEngine->setOption" is not called

    thus option is not set.

    I tryed the qt 4.8 multicast sender and I saw the same thing.
    (http://qt-project.org/doc/qt-4.8/network-multicastsender.html)

    Here is my environnement:
    compile OS: Windows XP
    execute OS: Windows XP
    Qt version: 4.8.1
    compiler: mingw
    build type: debug

    notes:
    I did the same test under linux mint 12 and had the same problem.
    I had the same problem also with Qt version 4.8.0

    Does anyone encountered this problem ?
    Is this a bug ?
    Is there a workaround ?

    Thanks
    Renaud



  • I'm having the same problem with a QTcpSocket.
    I create a new socket and then try to set QAbstractSocket::KeepAliveOption to 1.
    @
    m_pTcpSocket = new QTcpSocket(this);
    m_pTcpSocket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
    int test = m_pTcpSocket->socketOption(QAbstractSocket::KeepAliveOption).toInt();
    @
    it stays at 0.

    The problem for me is the same as Renauds. In QAbstractSocket::setSocketOption(..) the check
    @
    if (!d_func()->socketEngine)
    return;
    @
    always causes the function to return without changing the socket option.

    Anyone got an idea what I might be doing wrong?



  • Found the problem. You can only set the socket option after the connected signal.
    So this works:
    @
    SomeClass::ConnectToSomething()
    {
    m_pTcpSocket = new QTcpSocket(this);
    m_pTcpSocket->connectToHost(m_sHost, m_uPort);
    }

    SomeClass::SlotOnConnectedSignalReceived()
    {
    m_pTcpSocket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
    int test = m_pTcpSocket->socketOption(QAbstractSocket::KeepAliveOption).toInt();
    }
    @
    This doesn't work:
    @
    m_pTcpSocket = new QTcpSocket(this);
    m_pTcpSocket->setSocketOption(QAbstractSocket::KeepAliveOption, 1);
    int test = m_pTcpSocket->socketOption(QAbstractSocket::KeepAliveOption).toInt();
    m_pTcpSocket->connectToHost(m_sHost, m_uPort);
    @



  • Hi,
    setSocketOption is useful function. I have used it for extension rcv and snd buffer in QUdpSocket, because i had problem with fast incoming packets and losing it, here is the code:

    udpSocket->setSocketOption(QAbstractSocket::SendBufferSizeSocketOption, SNDBUF_SIZE_UDP);
    udpSocket->setSocketOption(QAbstractSocket::ReceiveBufferSizeSocketOption, RCVBUF_SIZE_UDP);

    It works fine, when app are running on the same PC with local addresses 127.0.0.1. If I trying it on two PC throw local network, that functions doesn´t work. Default buffer for QUdpSocket has 8 kB and it is very few. I am using Qt ver 5.3.
    Thanks for your advice,
    Petr


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.