Read packet from QTcpSocket



  • Hello... I would like to read a packet from QTcpSocket... I have successfully connected with server which is supposed to send a packet... I must read and parse that packed... How can I read it and parse it?

    Packet example:
    25 00 00 50 00 00 0E 70 82 27 11 5B 5F E5 28 E6
    00 00 00 BF 00 00 00 8F 44 3E 0F DA 32 6B 2B 7F
    FF C6 03 A3 25 1D 0C EF 6A BE 00

    Parsed:
    [25 00] - Size
    [00 50] - Opcode
    [00] - Security Count
    [00] - Security Crc
    [0E] - Flag
    [70 82 27 11 5B 5F E5 28] - Blowfish
    [E6 00 00 00] - Count Seed
    [BF 00 00 00] - CRC Seed
    [8F 44 3E 0F] - Seed 1
    [DA 32 6B 2B] - Seed 2
    [7F FF C6 03] - Seed 3
    [A3 25 1D 0C] - Seed 4
    [EF 6A BE 00] - Seed 5



  • I tried to read data with following code but it always crash at memmove...

    @
    private:
    char recvBuffer[8192];
    int recvIndex;@

    @void MainWindow::readData()
    {
    QDataStream in(sSocket);
    in.setVersion(QDataStream::Qt_5_2);

    // Get the number of bytes available
    int bytesAvailable = sSocket->bytesAvailable();

    // Read data
    in.readRawData(recvBuffer + recvIndex, 8192 - recvIndex);

    // Processing data
    int bytesProcessed = 0;
    recvIndex += bytesAvailable;

    do {
    bytesProcessed = onData(recvBuffer, recvIndex);

      if(bytesProcessed == 0)
        {
        }
      else if(bytesProcessed == recvIndex)
        {
         recvIndex = 0;
        }
      else
        {
          memmove(recvBuffer, recvBuffer + bytesProcessed, recvIndex - bytesProcessed); // App crashes here
    
          recvIndex -= bytesProcessed;
        }
    }
    

    while(bytesProcessed && recvIndex);
    }@


Log in to reply
 

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