Hello
This is my requestor code
#include "ndds/ndds_requestreply_cpp.h"
#include <iostream>
#include "idl/Primes.h"
#include "idl/PrimesSupport.h"
#include "idl/PrimesPlugin.h"
#include "ndds/ndds_namespace_cpp.h"
#include <QTime>
//#include <stdio.h>
//#include <stdlib.h>
#include <sstream>
using namespace connext;
int main()
{
DDS::WaitSet ws;
int domain_id = 1;
// Create a DomainParticipant
DDS::DomainParticipant * participant =
DDS::DomainParticipantFactory::get_instance()->create_participant(
domain_id, DDS::PARTICIPANT_QOS_DEFAULT,
NULL, DDS::STATUS_MASK_NONE);
if (participant == NULL)
{
std::cout<<"participant not created"<<std::endl;
}
else
{
//std::cout<<"participant created"<<std::endl;
// Create a Requester
Requester<Foo, Bar> * requester;
requester = new Requester<Foo, Bar>(participant, "TestService");
// Send request
for(int i = 1;i <= 10000;i++)
{
WriteSample<Foo> request;
request.data().count = i;
std::string buffer1 = "A Request";
std::ostringstream ostr;
ostr << request.data().count;
buffer1 += ostr.str();
ostr.str("");
//strcpy(request.data().message, "A Request"+ (request.data().count));
strcpy(request.data().message,buffer1.data());
requester->send_request(request);
// Create a reply Sample
Sample<Bar> reply;
// Receive reply (wait for it and get the sample)
DDS_Duration_t MAX_WAIT;
MAX_WAIT.sec = 1;
bool received = requester->receive_reply(reply, MAX_WAIT);
if (received)
{
if(reply.info().valid_data)
{
std::cout << "Received reply: " << reply.data().message << std::endl;
}
else
{
std::cout << "Received invalid reply" << std::endl;
}
}
else
{
std::cout << "Reply not received" << std::endl;
}
//sleep(1);
}
}
}
This is my replier code
#include "ndds/ndds_requestreply_cpp.h"
#include <iostream>
#include "idl/Primes.h"
#include "idl/PrimesSupport.h"
#include "idl/PrimesPlugin.h"
#include "ndds/ndds_namespace_cpp.h"
#include <sstream>
using namespace connext;
int main()
{
int domain_id = 1;
// Create a DomainParticipant
DDS::DomainParticipant * participant =
DDS::DomainParticipantFactory::get_instance()->create_participant(
domain_id, DDS::PARTICIPANT_QOS_DEFAULT,
NULL, DDS::STATUS_MASK_NONE);
// Create a Replier (if creation fails, the constructor throws exception)
Replier<Foo, Bar> * replier =
new Replier<Foo, Bar>(participant, "TestService");
DDS_Duration_t MAX_WAIT;
MAX_WAIT.sec = 1;
int i = 1;
while(1)
{
Sample<Foo> request;
// Receive one request
bool received = replier->receive_request(request, MAX_WAIT);
if (!received)
{
std::cout << "Requests not received" << std::endl;
//return false;
}
// A WriteSample automatically initializes and finalizes
// the data using the TypeSupport (in this case BarTypeSupport)
WriteSample<Bar> reply;
request.data().count = i;
std::string buffer1 = request.data().message;
std::ostringstream ostr;
ostr << reply.data().count;
buffer1 += ostr.str();
ostr.str("");
if (request.info().valid_data)
{
//sprintf(reply.data().message, "Reply for %s", request.data().message);
sprintf(reply.data().message, buffer1.data() );
// Send a reply for that request
replier->send_reply(reply, request.identity());
std::cout << "sent reply: " << reply.data().message << std::endl;
// Note: a replier can send more than one reply for the same request
}
i++;
//sleep(1);
}
}
First time my both program runs perfectly. As you can see in my code that i have a fixed for loop for requestor and replier runs in infinite loop. when i am agian started my requestor
Then after some time my replier crash with giving error
terminate called after throwing an instance of 'connext::TimeoutException'
what(): Replier(TestServiceReply, TestServiceRequest)::send_reply failure caused by EntityUntypedImpl::send_sample:!DataWriter write timeout
EntityUntypedImpl::send_sample:!DataWriter write timeout
Replier(TestServiceReply, TestServiceRequest)::send_reply:!failed (see previous errors)
and after that my requestor also crash by throwing error
terminate called after throwing an instance of 'connext::TimeoutException'
what(): Requester(TestServiceRequest, TestServiceReply)::send_request failure caused by EntityUntypedImpl::send_sample:!DataWriter write timeout
EntityUntypedImpl::send_sample:!DataWriter write timeout
Requester(TestServiceRequest, TestServiceReply)::send_request:!failed (see previous errors)
Please let we know the issue as soon as possible
Thanks
Bhawna Popli
Hi Bhawna,
The timeout exception that you're seeing usually indicates that a DataWriter—the Requester and Replier both use a DataWriter to send requests and replies—is filling up its queue with samples that can't reliably deliver fast enough. See the documentation for DataWriter::write(). This can also be useful: Which QoS parameters are important to tune for throughput testing?
However I saw that you have commented out the following line:
The code that follows after that is not correct, because it's sending a reply for the previous request. If you want to wait longer, you should go back to
receive_request.
I hope this help.
Regards,
Alex