Skip to content

tiepologian/MQ

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MQ

C++ POSIX Message Queues wrapper

Features

  • C++11 (lambdas)
  • header-only
  • multi-threaded
  • asynchronous

Installation

MQ is a header-only library. You don't need to build anything to install it. Simply add the header file to your include path and include "MQ.h":

#include "MQ.h"

The MQ library needs to be linked to the rt and pthread libraries, so if you save your file as main.cpp, you can compile it by running:

g++ --std=c++11 -O3 main.cpp -lrt -lpthread

Usage

Server

Create a server endpoint by calling the MQ constructor. The constructor excepts an ID (std::string) and the endpoint type:

MQ *messageQ = new MQ("example", MQ::EndpointType::Server);

Listen for incoming messages by calling the listen() method, which will call the provided lambda when a message is received:

messageQ->listen([](std::string message){
    std::cout << "Received: " << message << std::endl;
});

Send a message to the client by calling the sendMessage() method:

messageQ->sendMessage("Hello from the server!");
Client

Create a client endpoint by passing the appropriate type to the constructor:

MQ *client = new MQ("example", MQ::EndpointType::Client);

Send a message to the server:

client->sendMessage("Hello from the client!");

Read the response from the server:

std::cout << "Received: " << client->readMessage() << std::endl;

About

C++ POSIX Message Queues wrapper

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages