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. Two way comms via socket?
Forum Updated to NodeBB v4.3 + New Features

Two way comms via socket?

Scheduled Pinned Locked Moved Solved General and Desktop
28 Posts 4 Posters 1.6k Views 3 Watching
  • 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.
  • KroMignonK KroMignon

    @SPlatten said in Two way comms via socket?:

    So the question changes now, since A is telling me that it has written 55 bytes with the bytesWritten signal, where is the data going?

    Into the TCP socket output buffer, did you disable Naggle's algorithm or do a QTcpSocket::flush()?

    [EDIT] By the way, are you sure you are capturing the right traffic on WireShark? (tcp port 8123)

    SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #21

    @KroMignon , no what's Naggle's algorithm ?

    Wireshark must be ok, because the only address and port I'm sending JSON on is 8123

    A sample from Wireshark:

    19	2.131440	::1	::1	TCP	131	50625 → 8123 [PSH, ACK] Seq=59 Ack=1 Win=407744 Len=55 TSval=15333115 TSecr=15331092
    

    This is from 50625 -> 8123, no idea what 50625 is? Then immediately after this entry in Wireshark is:

    20	2.131460	::1	::1	TCP	76	8123 → 50625 [ACK] Seq=1 Ack=114 Win=407680 Len=0 TSval=15333115 TSecr=15333115
    

    Kind Regards,
    Sy

    KroMignonK JonBJ 2 Replies Last reply
    0
    • SPlattenS SPlatten

      @KroMignon , no what's Naggle's algorithm ?

      Wireshark must be ok, because the only address and port I'm sending JSON on is 8123

      A sample from Wireshark:

      19	2.131440	::1	::1	TCP	131	50625 → 8123 [PSH, ACK] Seq=59 Ack=1 Win=407744 Len=55 TSval=15333115 TSecr=15331092
      

      This is from 50625 -> 8123, no idea what 50625 is? Then immediately after this entry in Wireshark is:

      20	2.131460	::1	::1	TCP	76	8123 → 50625 [ACK] Seq=1 Ack=114 Win=407680 Len=0 TSval=15333115 TSecr=15333115
      
      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #22

      @SPlatten said in Two way comms via socket?:

      no what's Naggle's algorithm ?

      As written earlier (https://forum.qt.io/post/639857), this is the TCP algorithm which handles transmission rules to avoid sending too much small packets.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      2
      • SPlattenS SPlatten

        @KroMignon , no what's Naggle's algorithm ?

        Wireshark must be ok, because the only address and port I'm sending JSON on is 8123

        A sample from Wireshark:

        19	2.131440	::1	::1	TCP	131	50625 → 8123 [PSH, ACK] Seq=59 Ack=1 Win=407744 Len=55 TSval=15333115 TSecr=15331092
        

        This is from 50625 -> 8123, no idea what 50625 is? Then immediately after this entry in Wireshark is:

        20	2.131460	::1	::1	TCP	76	8123 → 50625 [ACK] Seq=1 Ack=114 Win=407680 Len=0 TSval=15333115 TSecr=15333115
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #23

        @SPlatten said in Two way comms via socket?:

        what's Naggle's algorithm ?

        It's Nagle's algorithm, as @KroMignon wrote :)

        However, it is "unusual" to disable this on a socket, it defaults to on for a good reason. If @KroMignon says

        You have to call QTcpSocket::flush() to force data sending to counterpart.

        and that works I would use that rather then changing the socket option....

        KroMignonK SPlattenS 2 Replies Last reply
        0
        • JonBJ JonB

          @SPlatten said in Two way comms via socket?:

          what's Naggle's algorithm ?

          It's Nagle's algorithm, as @KroMignon wrote :)

          However, it is "unusual" to disable this on a socket, it defaults to on for a good reason. If @KroMignon says

          You have to call QTcpSocket::flush() to force data sending to counterpart.

          and that works I would use that rather then changing the socket option....

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by
          #24

          @JonB said in Two way comms via socket?:

          However, it is "unusual" to disable this on a socket

          It depends, there are always use cases for this: localhost or local network sockets

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          1 Reply Last reply
          0
          • JonBJ JonB

            @SPlatten said in Two way comms via socket?:

            what's Naggle's algorithm ?

            It's Nagle's algorithm, as @KroMignon wrote :)

            However, it is "unusual" to disable this on a socket, it defaults to on for a good reason. If @KroMignon says

            You have to call QTcpSocket::flush() to force data sending to counterpart.

            and that works I would use that rather then changing the socket option....

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #25

            @JonB , I've added:

            psckReceiver->flush();
            

            After write and also added the call to:

            mpsckReceiver = new QTcpSocket();
            mpsckReceiver->setSocketOption(QAbstractSocket::LowDelayOption, 1);
            

            Still the same, A is receiving but the Ack message is not appearing in WireShark.

            Kind Regards,
            Sy

            JonBJ KroMignonK 2 Replies Last reply
            0
            • SPlattenS SPlatten

              @JonB , I've added:

              psckReceiver->flush();
              

              After write and also added the call to:

              mpsckReceiver = new QTcpSocket();
              mpsckReceiver->setSocketOption(QAbstractSocket::LowDelayOption, 1);
              

              Still the same, A is receiving but the Ack message is not appearing in WireShark.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #26

              @SPlatten
              Then by all means try the socket option, as I said I don't know whether that has the same effect. Once neither flushing nor disabling Nagle works, whatever your issue it is something else.

              1 Reply Last reply
              0
              • SPlattenS SPlatten

                @JonB , I've added:

                psckReceiver->flush();
                

                After write and also added the call to:

                mpsckReceiver = new QTcpSocket();
                mpsckReceiver->setSocketOption(QAbstractSocket::LowDelayOption, 1);
                

                Still the same, A is receiving but the Ack message is not appearing in WireShark.

                KroMignonK Offline
                KroMignonK Offline
                KroMignon
                wrote on last edited by
                #27

                @SPlatten said in Two way comms via socket?:

                Still the same, A is receiving but the Ack message is not appearing in WireShark.

                So there are not so many options in my eyes:

                • you are sending on wrong socket
                • the socket is closed (did you check return value of QTcpSocket::write() ?)
                • the event loop is locked, QTcpSocket requires a working event queue to work.

                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                SPlattenS 1 Reply Last reply
                0
                • KroMignonK KroMignon

                  @SPlatten said in Two way comms via socket?:

                  Still the same, A is receiving but the Ack message is not appearing in WireShark.

                  So there are not so many options in my eyes:

                  • you are sending on wrong socket
                  • the socket is closed (did you check return value of QTcpSocket::write() ?)
                  • the event loop is locked, QTcpSocket requires a working event queue to work.
                  SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by SPlatten
                  #28

                  @KroMignon , I modified the onSendJSON slot:

                  void clsModule::onSendAck(const QJsonObject& crobjJSON, QTcpSocket* psckReceiver) {
                      QJsonObject::const_iterator citrFound = crobjJSON.find(clsJSON::mscszMsgType);
                  
                      if ( citrFound == crobjJSON.end() ) {
                          return;
                      }
                      QString strAck(clsJSON::mscszAck + citrFound.value().toString());
                      QJsonObject objAck;
                      objAck.insert(clsJSON::mscszAddrTo, cstrGetAlias());
                      objAck.insert(clsJSON::mscszMsgType, strAck);
                      objAck.insert(clsJSON::mscszSource, clsJSON::mscszXMLMPAM);
                  qdbg() << "clsModule::onSendAck: " << QJsonDocument(objAck).toJson(QJsonDocument::Compact);
                      if ( mblnReady != true ) {
                          sendLater(cstrGetAlias(), objAck);
                      } else if ( psckReceiver != nullptr ) {
                          QAbstractSocket::SocketState eState(psckReceiver->state());
                  
                          if ( eState == QAbstractSocket::ConnectedState ) {
                              QByteArray arybytMsg(QJsonDocument(objAck).toJson(QJsonDocument::Compact));
                              qint64 int64Write = psckReceiver->write(arybytMsg);
                  qdbg() << "clsModule::onSendAck, int64Write: " << int64Write;
                              psckReceiver->flush();
                          }
                      }
                  }
                  

                  Now its working, annoyingly I'm not sure what I've changed that has fixed it...Thank you to @KroMignon and @JonB.

                  Kind Regards,
                  Sy

                  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