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. Increase TCP packet sending speed

Increase TCP packet sending speed

Scheduled Pinned Locked Moved Solved General and Desktop
tcptcp packettcpsockettcpservernetwork socket
4 Posts 3 Posters 144 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.
  • J Offline
    J Offline
    Joe von Habsburg
    wrote on 18 Apr 2025, 05:26 last edited by Joe von Habsburg
    #1

    hello, I am sending a file with tcp but the maximum I can see is 50Mbps. when I send the same file with a short code in python, I can see 300Mbps. how can I increase this file sending speed?

    void FileTransfer::sendFile(QString path)
    {
        qDebug() << "FileTransfer::sendFile" << path;
    
        if(!_client->isOpen()){
            return;
        }
    
        QFile file(path);
        if(!file.open(QIODevice::ReadOnly)){
            return;
        }
    
        QFileInfo fileInfo(file);
        QString FileNameWithExt(fileInfo.fileName());
        qint64 len;
        while (!file.atEnd()) {
            QByteArray fileData = file.readAll();
            len = _client->write(fileData, fileData.size());
        }
    
        QString msg = "File has been sent : " + FileNameWithExt+ "\nFile Size : " + QString::number(file.size());
        emit sendResponses(msg, len);
    }
    

    also it tells me here that it has sent the file but the other party has not received it yet. why could that be?

    1 Reply Last reply
    0
    • A Online
      A Online
      Axel Spoerl
      Moderators
      wrote on 18 Apr 2025, 06:21 last edited by
      #2

      Which class is _client, which version of Qt are you using on which OS, which is the Python code?

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Joe von Habsburg
        wrote on 18 Apr 2025, 06:48 last edited by Joe von Habsburg
        #3

        @Axel-Spoerl said in Increase TCP packet sending speed:

        Which class is _client,

        its, QTcpSocket

        @Axel-Spoerl said in Increase TCP packet sending speed:

        which version of Qt

        qt6.6

        @Axel-Spoerl said in Increase TCP packet sending speed:

        which is the Python code?

        import socket
        import struct
        
        def send_file(host, port, file_path):
            try:
                client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                client_socket.connect((host, port))
                
                with open(file_path, "rb") as file:
                    while chunk := file.read(1024): 
                        client_socket.sendall(chunk)
                
                client_socket.close()
            except Exception as e:
                print(f"error: {e}")
        
        
        HOST = "192.168.1.10"
        PORT = 5001 
        FILE_PATH = "plus_45.bin"  
        
        send_file(HOST, PORT, FILE_PATH)
        
        
        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 18 Apr 2025, 07:05 last edited by
          #4

          How large is the file? When it's very large - with Qt you load it into memory at once and then copy it again, with python you send it in chunks

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          3
          • J Joe von Habsburg has marked this topic as solved 30 days ago

          1/4

          18 Apr 2025, 05:26

          • Login

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