Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8589505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:04:25+00:00 2026-06-11T23:04:25+00:00

I have a server application which sends some xor encrypted strings . I am

  • 0

I have a server application which sends some xor encrypted strings. I am reading them from my QT client application. Sometimes, the server is slower and I am not able to receive the entire string. I have tried something like below but it gets stuck ( see the comment below). How can I wait until I have the entire data. I tried bytesAviable() but then again i get stuck (infinite loop)

QTcpSocket * sock = static_cast<QTcpSocket*>(this->sender());
if (key == 0)
{
    QString recv(sock->readLine());
    key = recv.toInt();
    qDebug() << "Cheia este " << key;

    char * response = enc_dec("#AUTH|admin|admin",strlen("#AUTH|admin|admin"),key);
    sock->write(response);
}
else
{
    busy = true;
    while (sock->bytesAvailable() > 0)
    {
        unsigned short word;
        sock->read((char*)(&word),2);
        qDebug()<<word;
        //Sleep(100); if i do this than it works great!
        QByteArray bts = sock->read(word);
        while (bts.length() < word)
        {
            char bit; //here get's stuck
            if (sock->read(&bit,1) > 0)
                bts.append(bit);
            sock->flush();
        }

        char * decodat = enc_dec((char*)bts.data(),bts.length() - 2,key);
        qDebug() << decodat;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:04:26+00:00Added an answer on June 11, 2026 at 11:04 pm

    I offer you to do the following:

    QObject::connect(this->m_TCPSocket, SIGNAL(readyRead()), this, SLOT(processRecivedDatagrams()));
    

    Some explanation:

    1. It is convinient to create a class instance of which will manage network;
    2. One has the member which is pointer on TCPSocket;
    3. In constructor implement connection of signal from socket readyRead() which is emmited when needed data was delivered with SLOT(processRecivedDatagrams()). which is responsible for processing recived datagrams/ in this case it is processRecivedDatagrams(), also implement this slot

    Mind that class which manages network has to inherit from QObject and also in its declaration include macrosQ_OBject` for MOC.

    update:

    i also offer you to store recived data in container like stack or queue this will allow you to synhronize sender and reciver (container in this case acts like buffer)

    // SLOT:
    
    
    void Network::processRecivedDatagrams(void)
    {
        if (!this->m_flagLocked) // use analog of mutex 
        {
            this->m_flagLocked = true; // lock resource
    
        QByteArray datagram;
        do 
        {
            datagram.resize(m_TCPSocket->pendingDatagramSize());
            m_TCPSocket->readDatagram(datagram.data(), datagram.size());
        }
                Qt::String YourString; // actualy I don`t remember how to declare Qt string
        while (m_TCPSocket->hasPendingDatagrams());
        QDataStream in (&datagram, QIODevice::ReadOnly);
    
            in  >> YourString
    
    
    
            --numberOfDatagrams;
        }
    
        this->m_flagLocked = false; // unlock resource
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a server application which I want to protect from being stopped by
I have a client server application in which the server and the client need
I have a client server application in which I need to transmit a user
We have a Server/Client cybercafe management application which used to work fine on Windows
I have a client-server Silverlight application, which is use Socets. I have server appliaction
We have already shipped a client (.NET WinForms) application which sends customer data to
I have some simple questions, I have a client-server application and data sent on
I have a server and a client application where the client sends a bunch
I have a File Transfer Application that sends files and folders. (Server - client)
I have a TCP server application in which on receiving an incoming connection, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.