Increase TCP packet sending speed
-
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?
-
Which class is
_client
, which version of Qt are you using on which OS, which is the Python code? -
@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)
-
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
-