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