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. Read packet from QTcpSocket
Qt 6.11 is out! See what's new in the release blog

Read packet from QTcpSocket

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.6k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0

      • Login

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