Skip to content
Snippets Groups Projects
Commit e2b4a2b0 authored by kopf's avatar kopf
Browse files

added for network clients loop with connection to server if first connection failed

parent 4046487d
No related branches found
No related tags found
No related merge requests found
...@@ -103,8 +103,22 @@ bool NetworkClient::SendLH(double llh_data, double lh_mc){ ...@@ -103,8 +103,22 @@ bool NetworkClient::SendLH(double llh_data, double lh_mc){
_theStream.connect(_serverAddress, _port); _theStream.connect(_serverAddress, _port);
if(!_theStream){ if(!_theStream){
Alert << "Could not send LH." << endmsg; //try it serveral times
return false; int counter=1;
while(!_theStream){
Warning << "Could not send LH " << counter << " time!" << endmsg;
Warning << "current error message " << _theStream.error().message() << endmsg;
std::this_thread::sleep_for( std::chrono::seconds(5));
_theStream.clear();
_theStream.connect(_serverAddress, _port);
counter++;
if (counter>20){
Alert << "Could not send LH last time." << endmsg;
return false;
}
Warning << "Try to send LH again!!!" << endmsg;
}
} }
if(std::isinf(llh_data) && llh_data > 0) if(std::isinf(llh_data) && llh_data > 0)
...@@ -127,11 +141,26 @@ bool NetworkClient::SendHeartbeat(){ ...@@ -127,11 +141,26 @@ bool NetworkClient::SendHeartbeat(){
_theHeartbeatStream.connect(_serverAddress, _port); _theHeartbeatStream.connect(_serverAddress, _port);
if(!_theStream){ int counter=0;
Alert << "Could not send heartbeat." << endmsg; while(!_theHeartbeatStream){
return false; Warning << "Could not send heartbeat " << counter << " time!" << endmsg;
Warning << "current error message " << _theHeartbeatStream.error().message() << endmsg;
std::this_thread::sleep_for( std::chrono::seconds(5));
_theHeartbeatStream.clear();
_theHeartbeatStream.connect(_serverAddress, _port);
counter++;
if (counter>20){
Alert << "Could not send heartbeat last time" << endmsg;
return false;
}
Warning << "Try to send heartbeat again!!!" << endmsg;
} }
// if(!_theStream){
// Alert << "Could not send heartbeat." << endmsg;
// return false;
// }
_theHeartbeatStream << NetworkClient::CLIENTMESSAGE_HEARTBEAT << "\n"; _theHeartbeatStream << NetworkClient::CLIENTMESSAGE_HEARTBEAT << "\n";
_theHeartbeatStream << _clientID << "\n"; _theHeartbeatStream << _clientID << "\n";
short answer; short answer;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment