ADD: added testing of client
This commit is contained in:
17
.vscode/launch.json
vendored
Normal file
17
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "gdb",
|
||||
"request": "launch",
|
||||
"name": "Launch Program",
|
||||
"target": "./build/SimControlApplication",
|
||||
"cwd": "${workspaceRoot}",
|
||||
"valuesFormatting": "parseText"
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
@@ -21,15 +22,16 @@ namespace SimControl {
|
||||
class SimControl{
|
||||
|
||||
public:
|
||||
SimControl(const std::string &addr,const std::int16_t port);
|
||||
|
||||
SimControl( std::string addr, ushort port);
|
||||
~SimControl();
|
||||
|
||||
private:
|
||||
|
||||
void MainFunction_();
|
||||
|
||||
void HandleMessage(std::string msg);
|
||||
|
||||
std::shared_ptr<DirectCommunication::DirectCommunicationClient> TCPClient_;
|
||||
std::unique_ptr<DirectCommunication::DirectCommunicationClient> TCPClient_;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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