Planned maintenance has been done but it did not solve the problem. So work will continue on this and a new time for trying updates will be announced asap.

QtcpSocket: error0>directly send error



  • 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


  • Qt Champions 2018

    Hi @lengjianhanshuang,

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

    Regards



  • @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.



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


  • @lengjianhanshuang

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



  • @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?



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

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



  • @lengjianhanshuang

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



  • @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.


Log in to reply