ADD: added some changes to client and server
This commit is contained in:
@@ -18,6 +18,7 @@ namespace DirectCommunication
|
|||||||
|
|
||||||
context_ = zmq::context_t();
|
context_ = zmq::context_t();
|
||||||
socket_ = zmq::socket_t(context_,zmq::socket_type::client);
|
socket_ = zmq::socket_t(context_,zmq::socket_type::client);
|
||||||
|
socket_.set(zmq::sockopt::connect_timeout,500);
|
||||||
LOG_S(INFO)<< "tcp://"+serverAddress_+":"+std::to_string(port_);
|
LOG_S(INFO)<< "tcp://"+serverAddress_+":"+std::to_string(port_);
|
||||||
|
|
||||||
socket_.connect("tcp://"+serverAddress_+":"+std::to_string(port_));
|
socket_.connect("tcp://"+serverAddress_+":"+std::to_string(port_));
|
||||||
@@ -25,7 +26,6 @@ namespace DirectCommunication
|
|||||||
|
|
||||||
socket_.set(zmq::sockopt::rcvtimeo,100);
|
socket_.set(zmq::sockopt::rcvtimeo,100);
|
||||||
socket_.set(zmq::sockopt::sndtimeo,500);
|
socket_.set(zmq::sockopt::sndtimeo,500);
|
||||||
socket_.set(zmq::sockopt::connect_timeout,500);
|
|
||||||
|
|
||||||
|
|
||||||
Worker_ = std::thread(&DirectCommunicationClient::workerFunc_,this);
|
Worker_ = std::thread(&DirectCommunicationClient::workerFunc_,this);
|
||||||
@@ -36,9 +36,12 @@ namespace DirectCommunication
|
|||||||
|
|
||||||
|
|
||||||
DirectCommunicationClient::~DirectCommunicationClient()
|
DirectCommunicationClient::~DirectCommunicationClient()
|
||||||
|
{
|
||||||
|
if (isConnected)
|
||||||
{
|
{
|
||||||
this->disconnect();
|
this->disconnect();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DirectCommunicationClient::disconnect()
|
void DirectCommunicationClient::disconnect()
|
||||||
{
|
{
|
||||||
@@ -49,8 +52,11 @@ namespace DirectCommunication
|
|||||||
isConnected = false;
|
isConnected = false;
|
||||||
MessageHandle_ = nullptr;
|
MessageHandle_ = nullptr;
|
||||||
stopWorker_ = true;
|
stopWorker_ = true;
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(150));
|
||||||
|
|
||||||
Worker_.join();
|
Worker_.join();
|
||||||
|
|
||||||
|
socket_.disconnect("tcp://"+serverAddress_+":"+std::to_string(port_));
|
||||||
socket_.close();
|
socket_.close();
|
||||||
context_.close();
|
context_.close();
|
||||||
|
|
||||||
@@ -93,7 +99,7 @@ namespace DirectCommunication
|
|||||||
zmq::message_t msg;
|
zmq::message_t msg;
|
||||||
auto recv = socket_.recv(msg,zmq::recv_flags::none);
|
auto recv = socket_.recv(msg,zmq::recv_flags::none);
|
||||||
|
|
||||||
if (recv > 0)
|
if (recv.has_value())
|
||||||
{
|
{
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
if (msg.to_string() == "CLOSE")
|
if (msg.to_string() == "CLOSE")
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ namespace DirectCommunication
|
|||||||
zmq::message_t msg;
|
zmq::message_t msg;
|
||||||
auto recv = socket_.recv(msg,zmq::recv_flags::none);
|
auto recv = socket_.recv(msg,zmq::recv_flags::none);
|
||||||
|
|
||||||
if (recv > 0)
|
if (recv.has_value())
|
||||||
{
|
{
|
||||||
if (!hasClient(msg.routing_id()))
|
if (!hasClient(msg.routing_id()))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user