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
Forum Update on Monday, May 27th 2025

Increase TCP packet sending speed

Scheduled Pinned Locked Moved Solved General and Desktop
tcptcp packettcpsockettcpservernetwork socket
4 Posts 3 Posters 147 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 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
    • Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on 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 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
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 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 on

          • Login

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