ADD: added test for direct zmq tcp and a first version of the server and client class

This commit is contained in:
Henry Winkel
2023-07-05 17:05:03 +02:00
parent f03c00a1a8
commit 828d038d5f
6 changed files with 289 additions and 11 deletions

View File

@@ -1 +1,48 @@
#pragma once
#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 DirectCommunicationClient
{
public:
DirectCommunicationClient(ushort port, std::string ServerAddress);
~DirectCommunicationClient();
void sendMessage(std::string msg);
std::unique_ptr<std::string> getLatestMessage();
private:
ushort port_;
std::string serverAddress_;
zmq::context_t context_;
zmq::socket_t socket_;
void workerFunc_();
std::thread Worker_;
std::atomic_bool stopWorker_;
WHISPER::threadSafeQueue<std::string> receivedMessages_;
};
}

View File

@@ -27,20 +27,22 @@ namespace DirectCommunication
void sendMessage(std::string msg);
std::unique_ptr<std::string> getLatestMessage();
int countClients();
private:
ushort port_;
zmq::context_t context_;
zmq::socket_t socket_;
void worker_();
void workerFunc_();
std::thread Worker_;
std::atomic_bool stopWorker_;
WHISPER::threadSafeQueue<std::string> receivedMessages_;
std::vector<std::uint32_t> connectedClients_;
bool hasClient(std::uint32_t);
bool hasClient(std::uint32_t clientId);
};