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. QtcpSocket: error0>directly send error
Forum Updated to NodeBB v4.3 + New Features

QtcpSocket: error0>directly send error

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 909 Views 1 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.
  • L Offline
    L Offline
    LengJianHanShuang
    wrote on 13 Aug 2019, 12:33 last edited by
    #1

    I use qt creator develop socket on my vm linux, when I connect the server device use net cable directly, and try to use qtcpsocket to connect to host(server device), it always pop out the error 0.
    When I use wireshark to get some information, It shows the "tcp out of order", dose anyone has idea
    about this situation, please help, thanks

    Follow your dreams

    A P 2 Replies Last reply 13 Aug 2019, 12:48
    0
    • L LengJianHanShuang
      13 Aug 2019, 12:33

      I use qt creator develop socket on my vm linux, when I connect the server device use net cable directly, and try to use qtcpsocket to connect to host(server device), it always pop out the error 0.
      When I use wireshark to get some information, It shows the "tcp out of order", dose anyone has idea
      about this situation, please help, thanks

      A Offline
      A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 13 Aug 2019, 12:48 last edited by
      #2

      Hi @lengjianhanshuang,

      most often it helps if you can post a minimal code example that shows your problem.

      Regards

      Qt has to stay free or it will die.

      L 1 Reply Last reply 13 Aug 2019, 12:59
      0
      • L LengJianHanShuang
        13 Aug 2019, 12:33

        I use qt creator develop socket on my vm linux, when I connect the server device use net cable directly, and try to use qtcpsocket to connect to host(server device), it always pop out the error 0.
        When I use wireshark to get some information, It shows the "tcp out of order", dose anyone has idea
        about this situation, please help, thanks

        P Offline
        P Offline
        Pl45m4
        wrote on 13 Aug 2019, 12:48 last edited by Pl45m4
        #3

        @lengjianhanshuang

        It's not a real error, it's more WireShark / TCP - protocol related.

        Every TCP Package as an ID (sequence number). Best case scenario is, when all packages arrive in the correct order, but in reality this is not the case everytime, so the receiver has to re-order the received packages.

        ... and WireShark detects that and throws a warning or info message.

        If you dont get any other errors, everything works fine.


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        0
        • A aha_1980
          13 Aug 2019, 12:48

          Hi @lengjianhanshuang,

          most often it helps if you can post a minimal code example that shows your problem.

          Regards

          L Offline
          L Offline
          LengJianHanShuang
          wrote on 13 Aug 2019, 12:59 last edited by
          #4

          @aha_1980

          like the following--------------------------------
          m_pcSocket = new QTcpSocket(this);
          if(nullptr != m_pcSocket) {
          m_pcSocket->connectToHost(QHostAddress("192.168.0.4),2023);

              connect(m_pcSocket,&QTcpSocket::connected, this, &CanClient::onConnected);
              connect(m_pcSocket,&QTcpSocket::readyRead, this, &CanClient::OnReadyRead);
              connect(m_pcSocket,QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error),this, &CanClient::OnSocketError);
          }
          

          Follow your dreams

          P 1 Reply Last reply 13 Aug 2019, 13:07
          0
          • L LengJianHanShuang
            13 Aug 2019, 12:59

            @aha_1980

            like the following--------------------------------
            m_pcSocket = new QTcpSocket(this);
            if(nullptr != m_pcSocket) {
            m_pcSocket->connectToHost(QHostAddress("192.168.0.4),2023);

                connect(m_pcSocket,&QTcpSocket::connected, this, &CanClient::onConnected);
                connect(m_pcSocket,&QTcpSocket::readyRead, this, &CanClient::OnReadyRead);
                connect(m_pcSocket,QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error),this, &CanClient::OnSocketError);
            }
            
            P Offline
            P Offline
            Pl45m4
            wrote on 13 Aug 2019, 13:07 last edited by
            #5

            @lengjianhanshuang

            According to this (https://doc.qt.io/qt-5/qabstractsocket.html#SocketError-enum) Error 0 means refused connection or timeout.


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            L 1 Reply Last reply 14 Aug 2019, 01:14
            1
            • L Offline
              L Offline
              LengJianHanShuang
              wrote on 13 Aug 2019, 13:31 last edited by
              #6

              @pl45m4
              thank you very mush for your reply, the the "directly send error" has other reason, it's hard for me to consider what leads it.
              Do you want other more information to conclute the reason?

              Follow your dreams

              1 Reply Last reply
              0
              • P Pl45m4
                13 Aug 2019, 13:07

                @lengjianhanshuang

                According to this (https://doc.qt.io/qt-5/qabstractsocket.html#SocketError-enum) Error 0 means refused connection or timeout.

                L Offline
                L Offline
                LengJianHanShuang
                wrote on 14 Aug 2019, 01:14 last edited by
                #7

                @pl45m4
                thanks very much for your help, it turns out the server device has problem, and It can connect now.
                but when I try to read data from socket on signal readyRead, it seems nothing can be get, could you please help me ?following is my code

                 QByteArray cCanInfoSerials = m_pcSocket->readAll();
                 QDataStream socketStream(m_pcSocket);
                 socketStream.setVersion(QDataStream::Qt_5_13);
                
                 // read to decide if the current board to be closed
                 // and set display's backlight level
                 // Data from Mainboard will be triggerred by DMSInfo module
                
                 // start an infinite loop
                 for (;;) {
                     // we start a transaction so we can revert to the previous state in case we try to read more data than is available on the socket
                     socketStream.startTransaction();
                     // we try to read the Can Data
                     socketStream >> cCanInfoSerials;
                     printf("Data Serail:");
                     for(int i=0;i<cCanInfoSerials.size();i++) {
                         printf(" %02x ", cCanInfoSerials.at(i));
                     }
                     printf("\n");
                     if (socketStream.commitTransaction()) {
                         // we successfully read some data
                         // we now need to make sure it's in fact a valid Can Data
                         uint DataSize = cCanInfoSerials.size();
                         qDebug() << "CanDataSize:"<<DataSize;
                

                ..............
                }

                Follow your dreams

                P 1 Reply Last reply 14 Aug 2019, 07:58
                0
                • L LengJianHanShuang
                  14 Aug 2019, 01:14

                  @pl45m4
                  thanks very much for your help, it turns out the server device has problem, and It can connect now.
                  but when I try to read data from socket on signal readyRead, it seems nothing can be get, could you please help me ?following is my code

                   QByteArray cCanInfoSerials = m_pcSocket->readAll();
                   QDataStream socketStream(m_pcSocket);
                   socketStream.setVersion(QDataStream::Qt_5_13);
                  
                   // read to decide if the current board to be closed
                   // and set display's backlight level
                   // Data from Mainboard will be triggerred by DMSInfo module
                  
                   // start an infinite loop
                   for (;;) {
                       // we start a transaction so we can revert to the previous state in case we try to read more data than is available on the socket
                       socketStream.startTransaction();
                       // we try to read the Can Data
                       socketStream >> cCanInfoSerials;
                       printf("Data Serail:");
                       for(int i=0;i<cCanInfoSerials.size();i++) {
                           printf(" %02x ", cCanInfoSerials.at(i));
                       }
                       printf("\n");
                       if (socketStream.commitTransaction()) {
                           // we successfully read some data
                           // we now need to make sure it's in fact a valid Can Data
                           uint DataSize = cCanInfoSerials.size();
                           qDebug() << "CanDataSize:"<<DataSize;
                  

                  ..............
                  }

                  P Offline
                  P Offline
                  Pl45m4
                  wrote on 14 Aug 2019, 07:58 last edited by
                  #8

                  @lengjianhanshuang

                  Is your signal getting triggered?
                  What is the error? Nothing happens or do you only receive wrong / no data?


                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  L 1 Reply Last reply 14 Aug 2019, 08:30
                  0
                  • P Pl45m4
                    14 Aug 2019, 07:58

                    @lengjianhanshuang

                    Is your signal getting triggered?
                    What is the error? Nothing happens or do you only receive wrong / no data?

                    L Offline
                    L Offline
                    LengJianHanShuang
                    wrote on 14 Aug 2019, 08:30 last edited by
                    #9

                    @pl45m4
                    thanks very mush for your reply, the error signal has been triggered, after I reset my server device, things get fine. it seemed the server get into some trouble, window system could't access same port on server device too.

                    Follow your dreams

                    1 Reply Last reply
                    1

                    1/9

                    13 Aug 2019, 12:33

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved