ADD: added zmq tcp server client classes
This commit is contained in:
@@ -88,6 +88,11 @@ add_library(whisper-com STATIC
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
include/DirectCommunicationServer.hpp
|
||||||
|
include/DirectCommunicationClient.hpp
|
||||||
|
|
||||||
|
src/DirectCommunicationServer.cpp
|
||||||
|
src/DirectCommunicationClient.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
1
include/DirectCommunicationClient.hpp
Normal file
1
include/DirectCommunicationClient.hpp
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#pragma once
|
||||||
49
include/DirectCommunicationServer.hpp
Normal file
49
include/DirectCommunicationServer.hpp
Normal 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);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
1
src/DirectCommunicationClient.cpp
Normal file
1
src/DirectCommunicationClient.cpp
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include <DirectCommunicationClient.hpp>
|
||||||
50
src/DirectCommunicationServer.cpp
Normal file
50
src/DirectCommunicationServer.cpp
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#include "zmq.hpp"
|
||||||
|
#include <DirectCommunicationServer.hpp>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace DirectCommunication
|
||||||
|
{
|
||||||
|
DirectCommunicationServer::DirectCommunicationServer(ushort port):port_(port)
|
||||||
|
{
|
||||||
|
|
||||||
|
context_ = zmq::context_t(1);
|
||||||
|
|
||||||
|
socket_ = zmq::socket_t(context_,zmq::socket_type::server);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DirectCommunicationServer::~DirectCommunicationServer()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectCommunicationServer::sendMessage(std::string msg)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<std::string> DirectCommunicationServer::getLatestMessage()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectCommunicationServer::worker_()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool DirectCommunicationServer::hasClient(std::uint32_t)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user