Subscribe/Publish problem

RCF support and general discussion.
Post Reply
usernobody
Posts: 4
Joined: Sun Mar 31, 2019 11:18 am

Subscribe/Publish problem

Post 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

usernobody
Posts: 4
Joined: Sun Mar 31, 2019 11:18 am

Re: Subscribe/Publish problem

Post by usernobody »

any body here??? :cry: :cry: :cry:

jarl
Posts: 238
Joined: Mon Oct 03, 2011 4:53 am
Contact:

Re: Subscribe/Publish problem

Post 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.
Kind Regards

Jarl Lindrud
Delta V Software
http://www.deltavsoft.com

usernobody
Posts: 4
Joined: Sun Mar 31, 2019 11:18 am

Re: Subscribe/Publish problem

Post 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:

jarl
Posts: 238
Joined: Mon Oct 03, 2011 4:53 am
Contact:

Re: Subscribe/Publish problem

Post 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
Kind Regards

Jarl Lindrud
Delta V Software
http://www.deltavsoft.com

usernobody
Posts: 4
Joined: Sun Mar 31, 2019 11:18 am

Re: Subscribe/Publish problem

Post by usernobody »

got it , thx for your job

Post Reply