93 lines
2.4 KiB
C++
93 lines
2.4 KiB
C++
#include "WHISPER/InternalUDPService.hpp"
|
|
#include "WHISPER/Messages/Message.hpp"
|
|
#include "zmq.hpp"
|
|
#include <iostream>
|
|
#include <loguru.hpp>
|
|
|
|
#include <WHISPER/Messages/Join.hpp>
|
|
#include <WHISPER/Messages/Protos/message.pb.h>
|
|
#include <memory>
|
|
|
|
|
|
/// variable for stopping the application
|
|
bool running = true;
|
|
|
|
/**
|
|
* @brief killhandler to set running to false on CTRL-C
|
|
*
|
|
* @param s - the signal to manage
|
|
*/
|
|
void killHandlerPing(int s) {
|
|
|
|
if (s == SIGINT) {
|
|
running = false;
|
|
}
|
|
}
|
|
|
|
|
|
int main()
|
|
{
|
|
// GOOGLE_PROTOBUF_VERIFY_VERSION;
|
|
|
|
|
|
|
|
WHISPER::Join join(1,1,WHISPER::MsgType::JOIN,WHISPER::SourceType::SHIP,8000,"192.168.0.19");
|
|
// std::string msg = join.serialize();
|
|
// LOG_S(INFO)<<" serialized Message is "<<msg.size();
|
|
// LOG_S(INFO)<<msg;
|
|
|
|
// messages::header::Message proto;
|
|
// proto.ParseFromString(msg);
|
|
|
|
// WHISPER::Message receivedMessage(msg);
|
|
|
|
// LOG_S(INFO)<<receivedMessage.msgType_;
|
|
|
|
// switch (receivedMessage.msgType_) {
|
|
// case WHISPER::MsgType::JOIN:
|
|
// WHISPER::Join receivedJoin(msg);
|
|
// LOG_S(INFO)<< "join message data afer reception "<< receivedJoin.port;
|
|
// break;
|
|
// }
|
|
auto receiver = std::make_shared<WHISPER::threadSafeQueue<WHISPER::Message>>();
|
|
WHISPER::InternalUDPService service(1,WHISPER::SHIP,8000,"192.168.0.255","192.168.0.19");
|
|
service.connect(receiver);
|
|
service.publish(join.serialize(), "management");
|
|
service.subscribe("data");
|
|
|
|
|
|
// zmq::context_t ctx(2);
|
|
// zmq::socket_t sock(ctx,zmq::socket_type::radio);
|
|
// sock.connect("udp://127.0.0.255:8000");
|
|
|
|
|
|
// std::string string = "hello world form 2";
|
|
// zmq::message_t msg(string.begin(),string.end());
|
|
// // memcpy (msg.data (), string.data(), string.size());
|
|
// LOG_S(INFO)<<"message contains "<<msg.str();
|
|
|
|
// zmq::context_t ctx(2);
|
|
// zmq::socket_t sock(ctx,zmq::socket_type::dish);
|
|
// sock.bind("udp://*:8000");
|
|
// zmq::message_t temp;
|
|
// sock.join("data");
|
|
|
|
|
|
|
|
int size = 0;
|
|
|
|
while (running) {
|
|
// zmq::message_t msg(string.begin(),string.end());
|
|
// msg.set_group("data");
|
|
// sock.send(msg,zmq::send_flags::none);
|
|
// service.publish(join.serialize(), "management");
|
|
|
|
if (size != receiver->size()) {
|
|
LOG_S(INFO)<<"received messages " << size;
|
|
size = receiver->size();
|
|
}
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
|
}
|
|
return 0;
|
|
} |