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 8972619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:15:33+00:00 2026-06-15T18:15:33+00:00

I have a client program and a server program that communicate using QSslSockets. In

  • 0

I have a client program and a server program that communicate using QSslSockets. In the server program I’m sending a string "Snameadded" if the client successfully connected,I also want to send it a list of the users on the server, but as a different message, I make two different blocks and write them separately but they are being read by the client as one

This is the code on the server:

void server::processMess(QString message)
{

    //Message type legend
    // [number]*** [name]*** [message]
    // number = 1, joining server for first time, rest is name
    // number = 2, split by "***", retrive name, receiving name, and rest is message
    // number = 3, disconnecting from server, resy is name


    bool successfullyConnected = false;
    QStringList temp = message.split("***");
    int num = temp.at(0).toInt();

    qDebug() << num;
    qDebug() << "size of socket list:" << myClientSockets.size();
    QString name = temp.at(1);
    if(num == 1)
    {
        QString name = temp.at(1);
        if(clientList.contains(name))
        {
            QByteArray block;
            block.append("Enameinvalid");

            QSslSocket *clientConnection = myClientSockets.at(myClientSockets.size() - 1);
            myClientSockets.pop_back();
            clientConnection->write(block);
            \

        }
        else
        {
            clientList.append(name);
            QByteArray block;
            block.append("Snameadded");
            successfullyConnected = true;


            QSslSocket *clientConnection = myClientSockets.at(myClientSockets.size() - 1);
            qDebug() << "Message created to send back to client: " << QString(block);
            clientConnection->write(block);

           /*
            ClientThread *thisClientThread = new ClientThread();
            thisClientThread->setClientConnection(clientConnection);
            myClientThreads.push_back(thisClientThread);
            connect(thisClientThread, SIGNAL(messageReceived(QString)), this, SLOT(processMess(QString)));
            thisClientThread->start();*/

        }
    }
    else if(num == 2)
    {
        //Direct message correctly
        QString receiver = temp.at(2);
        QSslSocket* receiverConnection = myClientSockets.at(clientList.indexOf(receiver));
        QByteArray block;
        block.append(message);
        receiverConnection->write(block);

    }
    else if(num == 3)
    {
        //Disconnect client
        updateServer(name + "disconnected");
        int position = clientList.indexOf(name);
        clientList.removeAt(position);
        myClientSockets.removeAt(position);
    }
    else
    {
        qDebug() << "Should never reach here";
    }

    if(successfullyConnected)
    {

        QByteArray block;
        block.append("UsersOnServer:");
        for(int i = 0; i < clientList.size(); ++i)
        {
            block.append(clientList.at(i));
            if(i < clientList.size() - 1)
            {
                block.append("***");
            }
        }
        for(int i = 0; i < myClientSockets.size(); ++i)
        {
            QSslSocket *receiverConnection = myClientSockets.at(i);
            receiverConnection->write(block);
        }
    }

    qDebug() << "Messaged received from client: " + message;
    updateServer("Messaged received from client: " + message);


    /*QSslSocket* thisConnection = myClientSockets.pop_back();

    QByteArray incoming = thisConnection->readAll();

    QString message = QString(incoming);

    qDebug() << "Message received from client: " + message;

    return;*/

    /*QByteArray in = tempSocket->readAll();

    QString message = QString(in);

    qDebug() << "Messaged received from client: " + message;
    updateServer(message);
*/


}

heres the code on my client side:
secureSocket->write(block);

if(secureSocket->waitForReadyRead(1000))
{
    QByteArray in = secureSocket->readAll();

    QString serverMess = QString(in);
    if(QString::compare(serverMess, "Snameadded", Qt::CaseSensitive) == 0)
    {
        returnVal = true;
        qDebug() << "added to server";
        connect(secureSocket, SIGNAL(readyRead()), this, SLOT(receiveMess()));
    }
    else if(QString::compare(serverMess, "Enameinvalid", Qt::CaseSensitive) == 0)
    {
        returnVal = false;
        qDebug() << "username already taken";
    }
    qDebug() << "*************Message from server:************** 1" << serverMess;
}
  • 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-15T18:15:34+00:00Added an answer on June 15, 2026 at 6:15 pm

    I fixed it I just did QSslSocket::waitForBytesWritten() so it would send the first byte array then the second one seperately.

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

Sidebar

Related Questions

I have a client/server program and I want to make sure that its components
I have a client-server program. I'm sending data like this: private void Sender(string s,TcpClient
I have a server-client program that use TCP connection to communicate. More than one
I have a Client program by tcp connection that send data to a server.
I have a program using odac(11.2) and oracle client 11.2. Now I want to
I currently have a chat client that communicates successfully with a server . I
I have a simple client server program that I made but the main issue
I'm building 2 programs (client/server) that communicate through FIFOs. Both programs have threads. When
I have a server/client program that communicates with serialized objects. When I run the
I have a client-server program that uses sockets to transfer information in a stateful

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.