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. Network: QUdpSocket setSocketOption seems not work

Network: QUdpSocket setSocketOption seems not work

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 7.0k 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.
  • R Offline
    R Offline
    renaud.h
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KA51O
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • K Offline
        K Offline
        KA51O
        wrote on last edited by
        #3

        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);
        @

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Croxman
          wrote on last edited by
          #4

          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

          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