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

  • Home
  • SEARCH
  • 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 8594929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:18:46+00:00 2026-06-12T00:18:46+00:00

I have a linux machine and a Windows machine I have a C++ program

  • 0

I have a linux machine and a Windows machine I have a C++ program witch acts as a server on the linux machine and a Qt application witch acts as a client on windows machine. I use the socket as a encryption key (basic xor encryption)

The problem is when I hit multiple times connect I get bogus strings. I think the problem is in qt application here is my code. I have tried to put a global flag busy to prevent the user from hitting the connect button manny times but this flag never gets triggered.

Why? Should I use a mutex? If yes how?

void MainWindow::performRead()
{
    QTcpSocket * sock = static_cast<QTcpSocket*>(this->sender());
    if (key == 0)
    {
    busy = true;
    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;
        QByteArray bts = sock->read(word);
        char * decodat = enc_dec((char*)bts.data(),bts.length() - 2,key);
        char testx[2];
        sock->peek(&testx[0],2);
        qDebug() << decodat;
        }
    }

    busy = false;
}

void MainWindow::on_pushButton_clicked()
{
    if (!busy)
    {
    key = 0;
    QTcpSocket * sock = new QTcpSocket();
    connect(sock,SIGNAL(readyRead()),this,SLOT(performRead()));
    sock->connectToHost("194.110.212.46",6550);
    }
    else qDebug()<<"Can't you see I am busy??" << endl;
}

char * enc_dec(char * str,int len, int key)
{
    unsigned char keys[2];
    keys[0] = (unsigned char)key;
    keys[1] = keys[0] ^ 255;
    char * nou = new char[len + 1];
    nou[len] = '\0';
    for (int i = 0; i < len; i++)
    {
        char tmpy = str[i] ^ keys[i % 2];
        nou[i] = tmpy;
    }
    return nou;
}
  • 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-12T00:18:47+00:00Added an answer on June 12, 2026 at 12:18 am

    Your code is pretty messed up, here are my suggestions:

    • Do not connect the socket on every button hit – you are overwriting what you had before, and do unnecessary work – TCP connection establishment is expensive,
    • Maybe have a “Connect” and “Disconnect” buttons, and only allow reading from socket when connection is established,
    • Try making sure everything works without your “encryption” first,
    • Use real encryption after that.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have compiled my application on Linux (Intel) machine using this command gcc –g
I have a linux C program that handles request sent to a TCP socket
My main goal: Collect specific information through the linux server on a windows machine.
I have a Windows XP machine and a Linux machine running Ubuntu. I share
I have two Linux Machine,1st is machine X ,other is machine Y i want
I have a linux vm which is our testing machine. as part of some
I have some files which need to be sftp from machine B ( linux
I have a machine with 8 GB RAM with 32 bit JVM on linux
I have a linux server has an ad-hoc wireless network for clients to connect
I have a linux server, I am looking to convert a .wma file to

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.