ADD: added zmq tcp server client classes

This commit is contained in:
Henry Winkel
2023-07-05 16:23:56 +02:00
parent b94f852137
commit f03c00a1a8
5 changed files with 106 additions and 0 deletions

View File

@@ -0,0 +1 @@
#pragma once

View File

@@ -0,0 +1,49 @@
#pragma once
#include "WHISPER/threadSafeQueue.hpp"
#include "zmq.hpp"
#include <atomic>
#include <cstdint>
#include <memory>
#include <string>
#include <sys/types.h>
#include <thread>
#include <vector>
namespace DirectCommunication
{
class DirectCommunicationServer
{
public:
DirectCommunicationServer(ushort port);
~DirectCommunicationServer();
void sendMessage(std::string msg);
std::unique_ptr<std::string> getLatestMessage();
private:
ushort port_;
zmq::context_t context_;
zmq::socket_t socket_;
void worker_();
std::thread Worker_;
std::atomic_bool stopWorker_;
WHISPER::threadSafeQueue<std::string> receivedMessages_;
std::vector<std::uint32_t> connectedClients_;
bool hasClient(std::uint32_t);
};
}