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

QtcpSocket: error0>directly send error

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 804 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.
  • LengJianHanShuangL Offline
    LengJianHanShuangL Offline
    LengJianHanShuang
    wrote on 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

    aha_1980A Pl45m4P 2 Replies Last reply
    0
    • LengJianHanShuangL LengJianHanShuang

      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

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 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.

      LengJianHanShuangL 1 Reply Last reply
      0
      • LengJianHanShuangL LengJianHanShuang

        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

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on 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
        • aha_1980A aha_1980

          Hi @lengjianhanshuang,

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

          Regards

          LengJianHanShuangL Offline
          LengJianHanShuangL Offline
          LengJianHanShuang
          wrote on 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

          Pl45m4P 1 Reply Last reply
          0
          • LengJianHanShuangL LengJianHanShuang

            @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);
            }
            
            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on 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

            LengJianHanShuangL 1 Reply Last reply
            1
            • LengJianHanShuangL Offline
              LengJianHanShuangL Offline
              LengJianHanShuang
              wrote on 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
              • Pl45m4P Pl45m4

                @lengjianhanshuang

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

                LengJianHanShuangL Offline
                LengJianHanShuangL Offline
                LengJianHanShuang
                wrote on 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

                Pl45m4P 1 Reply Last reply
                0
                • LengJianHanShuangL LengJianHanShuang

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

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

                  Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on 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

                  LengJianHanShuangL 1 Reply Last reply
                  0
                  • Pl45m4P Pl45m4

                    @lengjianhanshuang

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

                    LengJianHanShuangL Offline
                    LengJianHanShuangL Offline
                    LengJianHanShuang
                    wrote on 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

                    • Login

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