ADD: added testing of client
This commit is contained in:
@@ -3,24 +3,34 @@
|
||||
|
||||
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
namespace SimControl {
|
||||
|
||||
|
||||
SimControl::SimControl(const std::string &addr,const std::int16_t port)
|
||||
SimControl::SimControl( std::string addr, ushort port)
|
||||
{
|
||||
|
||||
TCPClient_ = std::make_shared<DirectCommunication::DirectCommunicationClient>(port,addr);
|
||||
TCPClient_ = std::make_unique<DirectCommunication::DirectCommunicationClient>(port,addr);
|
||||
TCPClient_->registerMessageCallback(std::bind(&SimControl::HandleMessage,this,std::placeholders::_1));
|
||||
TCPClient_->sendMessage("Hello Server");
|
||||
|
||||
}
|
||||
|
||||
SimControl::~SimControl()
|
||||
{
|
||||
TCPClient_ = nullptr;
|
||||
|
||||
}
|
||||
|
||||
void SimControl::HandleMessage(std::string msg)
|
||||
{
|
||||
|
||||
LOG_S(INFO)<<msg;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
18
src/main.cpp
18
src/main.cpp
@@ -1,7 +1,9 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
|
||||
#include <SimControl/SimControl.hpp>
|
||||
#include <loguru.hpp>
|
||||
|
||||
/// variable for stopping the application
|
||||
bool running = true;
|
||||
@@ -30,14 +32,26 @@ int main()
|
||||
sigIntHandler.sa_flags = 0;
|
||||
sigaction(SIGINT, &sigIntHandler, NULL);
|
||||
|
||||
ushort port = 3500;
|
||||
// SimControl::SimControl sc("127.0.0.1",5557);
|
||||
|
||||
SimControl::SimControl sc("127.0.0.255",8000);
|
||||
|
||||
DirectCommunication::DirectCommunicationClient client(port,"127.0.0.1");
|
||||
|
||||
client.sendMessage("Hello Server");
|
||||
|
||||
while (running) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
client.sendMessage("Hello Server");
|
||||
|
||||
std::string MessageString = client.getLatestMessage();
|
||||
LOG_S(INFO)<<MessageString;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
LOG_S(INFO)<<"end app";
|
||||
std::exit(0);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user