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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:10:28+00:00 2026-06-15T00:10:28+00:00

I’m working on a program where I have a one process called server and

  • 0

I’m working on a program where I have a one process called server and several processes called client that can connect to the server and send it messages< however for some reason my client won’t connect to my server:

This is the header file for the client class:

#ifndef CLIENT_H
#define CLIENT_H

#include <QString>
#include <string>
#include <QByteArray>
#include <mqueue.h>
#include <iostream>
#include "serveredialog.h"
#include "badudialog.h"
#include "../src/messages.h"

class Client
{
public:
    Client();
    void init(QString name);
    void sendMessage(QString mess);
private:
    char *myMailboxName, buf[MSG_SIZE];
    struct mq_attr attr;
    mqd_t mq_ownBox, mq_centralBox;

};

#endif // CLIENT_H

this is the client cpp file:

#include "Client.h"

using namespace std;

Client::Client()
{
    attr.mq_maxmsg = 10;
    attr.mq_msgsize = MSG_SIZE;
    attr.mq_flags = 0;
}

void Client::init(QString name)
{
    //Convert name into char*
    QByteArray byteArray = name.toUtf8();
    char str1[40];
    const char* tempr = byteArray.constData();
    strncpy(str1, tempr, sizeof(str1));
    myMailboxName = str1;

    //Create temp box to check if name available
    string tempS = myMailboxName;
    tempS += "new";
    const char* tempr1 = tempS.data();
    mq_unlink(tempr1);
    mq_ownBox = mq_open(tempr1, O_RDONLY | O_CREAT, S_IRWXU, &attr);
    mq_centralBox = mq_open(CENTRALBOX, O_RDWR);

    //Tell server that you are ready
    string tempS1 = str1;
    string tempS2 = "started:" + tempS1;
    const char* tempr2 = tempS2.data();
    sprintf(buf, tempr2);
    int tempI = mq_send(mq_centralBox, buf, strlen(buf), 0);
    cout << tempI;
    //Check for success
    if(tempI){
        ServerEDialog sd;
        sd.setModal(true);
        sd.exec();
    }
    else
    {
        //If success, wait for response fromserver
        while(1)
        {
            int tempI2 = mq_receive(mq_ownBox, buf, MSG_SIZE, 0);
            if(tempI2 != -1)
            {
                break;
            }
        }
        QString tempS3 = buf;

        //if invalid show error, otherwise create permanent mailbox
        if(tempS3 == "invalidname")
        {
            BadUDialog bd;
            bd.setModal(true);
            bd.exec();
        }
        else
        {
            mq_unlink(myMailboxName);
            mq_ownBox = mq_open(myMailboxName, O_RDONLY | O_CREAT, S_IRWXU, &attr);
        }
    }
}

void Client::sendMessage(QString mess)
{

}

This is my server header file:

#ifndef SERVER_H
#define SERVER_H

#include <QString>
#include <mqueue.h>
#include <QVector>
#include <QStringList>
#include <iostream>
#include "../src/messages.h"

class Server : public QObject
{
    Q_OBJECT
public:
    Server();
    void start();
private:
    void join(QString name);
    char buf[MSG_SIZE], msgSend[MSG_SIZE];
    QVector<mqd_t> mq_external;
    QVector<QString> users;
    mqd_t mq_central;
    struct mq_attr attr;


signals:
    void joined(QString name);

};

#endif // SERVER_H

This is my server cpp file:

#include "Server.h"

using namespace std;

Server::Server()
{
}

void Server::start(){

    attr.mq_maxmsg = 100;
    attr.mq_msgsize = MSG_SIZE;
    attr.mq_flags = 0;

    mq_unlink(CENTRALBOX);
    mq_central = mq_open(CENTRALBOX, O_RDONLY | O_CREAT, S_IRWXU, &attr);
    while(1)
    {
        //Wait to recieve message from user
        int tempMsgVal = mq_receive(mq_central, buf, MSG_SIZE, 0);
        if(tempMsgVal != -1)
        {
            cout << tempMsgVal;
        }

        if(tempMsgVal != -1){
            QString tempS = buf;
            QStringList tempSL = tempS.split(":");
            if(tempSL.size() == 2 && tempSL.at(0) == "started")
            {
                int x = 0;
                bool exists = false;
                for(int i = 0; i < mq_external.size(); i++)
                {
                    x = QString::compare(tempSL[1], users.at(i), Qt::CaseInsensitive);
                    if(x == 0)
                    {
                        exists = true;
                        break;
                    }
                }

                if(!exists)
                {
                    sprintf(buf,"joined");
                    QString tempS1 = tempSL[1] + "new";
                    QByteArray byteArray = tempS1.toUtf8();
                    const char* tempr = byteArray.constData();
                    mqd_t tempMQ = mq_open(tempr, O_RDWR);
                    int tempI = mq_send(tempMQ, buf, strlen(buf), 0);

                    join(tempSL[1]);
                }
                else
                {
                    sprintf(buf,"invalidname");
                    QString tempS1 = tempSL[1] + "new";
                    QByteArray byteArray = tempS1.toUtf8();
                    const char* tempr = byteArray.constData();
                    mqd_t tempMQ = mq_open(tempr, O_RDWR);
                    int tempI = mq_send(tempMQ, buf, strlen(buf), 0);
                }//Endelse
            }//Endif
        }//Endif

    }//Endwhile
}

void Server::join(QString name)
{
    emit joined(name);
}

This is the messages.h file which i include in both classes:

#ifndef MESSAGES_H
#define MESSAGES_H

#define MSG_SIZE 150
#define CENTRALBOX "/CentralMailBox"

#include <stdio.h>
#include <stdlib.h>

#endif // MESSAGES_H

Some of the code in the client and server class have to do with the gui, but I have tested that part and the relevant methods are called at the correct time.

My problem is that when I call in the first call the mq_send method in the client function, it’s returning and error and the same for the server class, Is there something I’m doing wrong when it comes to sending and receiving messages because I can’t figure it out for the life of me.

  • 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-15T00:10:29+00:00Added an answer on June 15, 2026 at 12:10 am

    I found out where I was going wrong, it’s UN-shown, but the mq_ownbox, used a name that i got from the gui, which i forgot to add ‘/’ to the beginning of, as for mq_central, setting the maxmsg to 100 caused the invalid arguement

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.