Session Object does not exist after RCF::createCallbackConne
Posted: Tue Apr 30, 2013 1:43 am
Hi
When I use callback connections, session objects doses not exist after RCF::createCallbackConnection.
Test code is like blow.
client->setname(test); <-- 1st call : create session obj at server side
RCF::createCallbackConnection(*client, callbackServer); <-- 2nd call : session obj exist.
client->print(); <-- 3rd call : Caught exception : session object does not exist.
client side)
RCF::RcfInitDeinit rcfInit;
RcfClient<I_CLIENT> *client;
RCF::RcfServer callbackServer(RCF::TcpEndpoint(0));
Client_reverseImpl client_serverimpl;
callbackServer.bind<I_CLIENT_REVERSE>(client_serverimpl);
callbackServer.start();
client = new RcfClient<I_CLIENT>(RCF::TcpEndpoint(serverip, serverport));
std::string test = "abcdef";
client->setname(test);
RCF::createCallbackConnection(*client, callbackServer);
client->print();
Server SIDE)
RCF::RcfInitDeinit rcfInit;
// Start a TCP server on port 50001, and expose MyServiceImpl.
Server_Impl myServiceImpl;
RCF::RcfServer server( RCF::TcpEndpoint("0.0.0.0", 50001) );
RCF::ThreadPoolPtr tpool(new RCF::ThreadPool(10));
server.setThreadPool(tpool);
server.bind<I_CLIENT>(myServiceImpl);
RCF::getObjectPool().setBufferCountLimit(0);
server.setOnCallbackConnectionCreated(onCallbackConnectionCreated);
server.start();
void onCallbackConnectionCreated(
RCF::RcfSessionPtr sessionPtr,
RCF::ClientTransportAutoPtr clientTransportPtr)
{
// Store the callback client transport in a global variable for later use.
RCF::Lock lock(gCallbackTransportMutex);
std::cout << "client is connected" << std::endl;
std::string &clientname = sessionPtr->getSessionObject<std::string>();
std::cout << "Session Client Name is : " << clientname << std::endl;
}
class Server_Impl
{
public:
void setname(std::string &data)
{
RCF::RcfSession & session = RCF::getCurrentRcfSession();
std::string & sessionClientName = session.getSessionObject<std::string>(true);
sessionClientName = data;
}
void print()
{
RCF::RcfSession & session = RCF::getCurrentRcfSession();
std::string & sessionClientName = session.getSessionObject<std::string>();
std::cout << "PRINT Session Client Name is : " << sessionClientName << std::endl;
}
};
INTERFACE)
RCF_BEGIN(I_CLIENT, "I_CLIENT")
RCF_METHOD_V1(void, setname, std::string &)
RCF_METHOD_V0(void, print);
RCF_END(I_CLIENT)
RCF_BEGIN(I_CLIENT_REVERSE, "I_CLIENT_REVERSE")
RCF_METHOD_R1(std::string, reverse, std::string)
RCF_END(I_CLIENT_REVERSE)
When I use callback connections, session objects doses not exist after RCF::createCallbackConnection.
Test code is like blow.
client->setname(test); <-- 1st call : create session obj at server side
RCF::createCallbackConnection(*client, callbackServer); <-- 2nd call : session obj exist.
client->print(); <-- 3rd call : Caught exception : session object does not exist.
client side)
RCF::RcfInitDeinit rcfInit;
RcfClient<I_CLIENT> *client;
RCF::RcfServer callbackServer(RCF::TcpEndpoint(0));
Client_reverseImpl client_serverimpl;
callbackServer.bind<I_CLIENT_REVERSE>(client_serverimpl);
callbackServer.start();
client = new RcfClient<I_CLIENT>(RCF::TcpEndpoint(serverip, serverport));
std::string test = "abcdef";
client->setname(test);
RCF::createCallbackConnection(*client, callbackServer);
client->print();
Server SIDE)
RCF::RcfInitDeinit rcfInit;
// Start a TCP server on port 50001, and expose MyServiceImpl.
Server_Impl myServiceImpl;
RCF::RcfServer server( RCF::TcpEndpoint("0.0.0.0", 50001) );
RCF::ThreadPoolPtr tpool(new RCF::ThreadPool(10));
server.setThreadPool(tpool);
server.bind<I_CLIENT>(myServiceImpl);
RCF::getObjectPool().setBufferCountLimit(0);
server.setOnCallbackConnectionCreated(onCallbackConnectionCreated);
server.start();
void onCallbackConnectionCreated(
RCF::RcfSessionPtr sessionPtr,
RCF::ClientTransportAutoPtr clientTransportPtr)
{
// Store the callback client transport in a global variable for later use.
RCF::Lock lock(gCallbackTransportMutex);
std::cout << "client is connected" << std::endl;
std::string &clientname = sessionPtr->getSessionObject<std::string>();
std::cout << "Session Client Name is : " << clientname << std::endl;
}
class Server_Impl
{
public:
void setname(std::string &data)
{
RCF::RcfSession & session = RCF::getCurrentRcfSession();
std::string & sessionClientName = session.getSessionObject<std::string>(true);
sessionClientName = data;
}
void print()
{
RCF::RcfSession & session = RCF::getCurrentRcfSession();
std::string & sessionClientName = session.getSessionObject<std::string>();
std::cout << "PRINT Session Client Name is : " << sessionClientName << std::endl;
}
};
INTERFACE)
RCF_BEGIN(I_CLIENT, "I_CLIENT")
RCF_METHOD_V1(void, setname, std::string &)
RCF_METHOD_V0(void, print);
RCF_END(I_CLIENT)
RCF_BEGIN(I_CLIENT_REVERSE, "I_CLIENT_REVERSE")
RCF_METHOD_R1(std::string, reverse, std::string)
RCF_END(I_CLIENT_REVERSE)