Subscribe/Publish problem
Posted: Sun Mar 31, 2019 12:00 pm
code segment
1, how to get the number of subscriber connections before any message sent
2. how to get the subscriber ip when it disconnect
Here I have two questions: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;
}
1, how to get the number of subscriber connections before any message sent
2. how to get the subscriber ip when it disconnect