Some communications are lost, when many small data is send



  • Hi again,

    during the last days I started to implement some TCP communication with the help of this Forum. Again, let me thank you very much for your help.

    Lets assume QTCPServer and QTCPSocket are connected and on the Server side, the incomming connecting socket ist stored as m_currentClient and a function startRead() is connected with the "readReady" Signal.

    My Server has many data, on which it does some fancy computations. The results are again many data segments, which has to be communicated to the Client = GUI.

    Ok, my idea is to send a unique QString identifier, that tells the Server what he has to do. This concept worked up to now, but now, i have to read more than 20 values, but that doesn't work anymore.
    Here is my small example

    @
    Client:
    for (unsigned int i=0;i<N;++i)
    {
    write("GIVEDATA\n"); // some unique identifier

     QByteArray p_ByteArray;
     QDataStream p_DataStream(&p_ByteArray, QIODevice::ReadWrite);
     p_DataStream << i_RoomID << i_WallID; // send two ints
     write(p_ByteArray);
    
     // wait for result
     waitForReadyRead();
    
     QByteArray p_ByteArray2;
     QDataStream p_DataStream2(&p_ByteArray2, QIODevice::ReadWrite);
     p_ByteArray2 = readLine();
    
    
     float p_Data;
     p_DataStream2 >> p_Data;
    
     printf("%d: %4.2f\n",i,p_Data); // First about 15 are correct, the zeros start to occur inbetween
    

    }

    Server:
    startRead()
    {
    QString p_Line;

     p_Line = QString::fromUtf8(m_currnetClient->readLine()).trimmed();
    
     if(p_Line.mid(0,8)=="GIVEDATA")
     {
          QByteArray p_ByteArray;
          QDataStream p_DataStream(&p_ByteArray, QIODevice::ReadWrite);
          p_ByteArray = m_currnetClient->readLine();
    
          int p_RoomID, p_WallID;
          p_DataStream >> p_RoomID >> p_WallID;
    
          QByteArray p_ByteArray2;
          QDataStream p_DataStream2(&p_ByteArray2, QIODevice::ReadWrite);
    
          p_DataStream2 << myData[p_RoomID][ p_WallID];     // std::vector<std::vector<float>>;
          m_currnetClient->write(p_ByteArray2);
     }
     else if ....
     else
          printf("I dont know what to do");
    

    @

    So thats the Code. The first values are correct, then some Zeros start to get read. Again, for a small amount of data it works, but more more data the communication seems to Clip or sth.

    Does anyone have an idea where to start.

    I have both Server and Client on the some Computer both with visual Studio an was in debug mode on both applications. I debuged from step to step and found out that the correct data is brougt to the stream, but the wrong data is received. Really strange .....

    Kind regards,
    curator


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.