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. TCP Connection Retransmition Problem
QtWS25 Last Chance

TCP Connection Retransmition Problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
tcptcp packettcp serversockettcpsocket
1 Posts 1 Posters 141 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 26 Jun 2024, 06:24 last edited by Joe von Habsburg
    #1

    I am working on a project. in this project I am using tcp client.

    When I send any message to the server, the server transmits messages to me in packets (total message length is always constant) . But most of the time there is a freeze. When I check via wireshark, I see that I get TCP Retransmission - TCP Dup ACK errors.

    C++ code :

    #include "client.h"
    
    Client::Client(QObject *parent)
        : QObject{parent}
    {
        _client = new QTcpSocket(this);
    
        connect(_client, &QTcpSocket::readyRead, this, &Client::readyRead);
    
    }
    
    Client::~Client()
    {
        _client->abort();
        _client->close();
    }
    
    void Client::connectToHost(QString address, int port)
    {
        if(_client->isOpen()){
            _client->disconnect();
        }
    
        REMOTE_ADDRESS = address;
        REMOTE_PORT = port;
    
        _client->connectToHost(REMOTE_ADDRESS, REMOTE_PORT);
    
        QTimer::singleShot(3000, this, &Client::sendHi);
    }
    
    void Client::disconnect()
    {
        _client->close();
        _client->abort();
        _client->flush();
    }
    
    void Client::readyRead()
    {
        if(_data.size() < _max_len){
            _data += _client->read(_max_len - _data.size());
        }
    
        if(_data.size() == _max_len){
            emit sendData(_data);
            _data.clear();
            QByteArray data = QString("hi").toUtf8();
            _client->write(data, data.size());
        }
        else if(_data.size() > _max_len){
            _data.clear();
            QByteArray data = QString("hi").toUtf8();
            _client->write(data);
        }
    }
    
    void Client::sendHi()
    {
        if(!_client->isOpen()){
            qDebug() << "Could not connect";
            return;
        }
    
        QByteArray data = QString("hi").toUtf8();
        _client->write(data,data.size());
        qDebug() << "First 'hi' has been sent : " << QDateTime::currentDateTime();
    }
    
    

    also when I run the same process on a simple python code, I get the same error less than my qt c++ code.

    Python code :

    import socket
    
    HOST = '192.168.1.10' 
    PORT = 5001             
    
    def receive_data(sock, length):
       
        data = b''
        while len(data) < length:
            more = sock.recv(length - len(data))
            if not more:
                raise EOFError('ERR')
            data += more
        return data
    
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
    sock.connect((HOST, PORT))
    print(f'{HOST}:{PORT} connected')
    
    num_samples = 4096
    
    for _ in range(10000):
        sock.sendall(b'hi')
        data = receive_data(sock, num_samples*4*2)
        time.sleep(.001)
    
    time.sleep(1)
    sock.close()
    
    

    why am i getting this error and how can i handle this error? what is your suggestion?

    1 Reply Last reply
    0

    1/1

    26 Jun 2024, 06:24

    • Login

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