Page 1 of 1

Subscribe/Publish problem

Posted: Sun Mar 31, 2019 12:00 pm
by usernobody
code segment
RCF::RcfInit rcfinit;
RCF::RcfServer server(RCF::TcpEndpoint(50001));
server.start();

typedef std::shared_ptr< RCF::Publisher<I_SOMEINTERFACE> > PublisherPtr;
RCF::PublisherParms pubParms;
pubParms.setOnSubscriberConnect(OnConnectCallback);
pubParms.setOnSubscriberDisconnect(OnDisConnectCallback);
PublisherPtrptr = server.createPublisher<I_SOMEINTERFACE>(pubParms);

////waiting subscriber connect here,server and client running on the same computer///
.....At this point the subscriber was connected to the server,
and OnConnectCallback has been called correctly。
//////

...At this point the publisher did not send any messages.
std::size_t subcount = PublisherPtrptr.getSubscriberCount(); --》problem here: getSubscriberCount() return 0

PublisherPtrptr->publish().SomeFunc(); -》The subscriber received the message correctly

subcount = PublisherPtrptr.getSubscriberCount(); -》ok, after any message sent, getSubscriberCount() return 1


//callback func here//
void OnDisConnectCallback(RCF::RcfSession &session, const std::string &Topic)
{
std::string ip = session.getClientAddress().string();
-》problem here: getClientAddress() got a runtime error "abort() has been called"

}

bool Onconnect(RCF::RcfSession &session, const std::string &Topic)
{
//this func running ok...
std::string ip = session.getClientAddress().string() ;
return true;
}
Here I have two questions:
1, how to get the number of subscriber connections before any message sent
2. how to get the subscriber ip when it disconnect

Re: Subscribe/Publish problem

Posted: Fri Apr 05, 2019 9:22 am
by usernobody
any body here??? :cry: :cry: :cry:

Re: Subscribe/Publish problem

Posted: Mon Apr 08, 2019 12:02 am
by jarl
Hi there,

For the first issue, with getSubscriberCount() returning 0, I'm unable to reproduce it in my test code here. One thing you could try though is to publish a ping to all subscribers, before getting the subscriber count:

Code: Select all

PublisherPtrptr.publish().getClientStub().ping();
, and see if that makes any difference.

As for the second issue, with the runtime error, I've been able to reproduce it, and have put in a fix in the code. I will post a download once the rest of the tests have run through.

Re: Subscribe/Publish problem

Posted: Tue Apr 09, 2019 10:03 am
by usernobody
thanks and ..
Can I add many topic to one subscription?
because createSubscription() will make a new connection to the sever, i don't want a lot connection.

and...
Sorry for my English, it comes from google translation. . . :lol:

Re: Subscribe/Publish problem

Posted: Wed Apr 10, 2019 12:42 am
by jarl
Currently you can only have one topic per subscription.

Here is a link to the latest download with a fix for the runtime error:

http://deltavsoft.com/downloads/RCF-3.1.301.zip

Re: Subscribe/Publish problem

Posted: Wed Apr 10, 2019 1:22 am
by usernobody
got it , thx for your job