Server-side Session Objects - Server
This sample demonstrates using RCF::RcfSession::getSessionObject()
and RCF::RcfServer::getServerObject()
, to maintain connection sessions and server sessions.
#include <iostream>
#include <RCF/RCF.hpp>
RCF_BEGIN(I_PrintService, "I_PrintService")
RCF_METHOD_V2(void, Print, const std::string&, const std::string &)
RCF_END(I_PrintService)
class ConnectionSession
{
public:
int mCallsMade = 0;
};
class ServerSession
{
public:
std::string mUserName;
int mCallsMade = 0;
};
typedef std::shared_ptr<ServerSession> ServerSessionPtr;
class PrintService
{
public:
void Print(const std::string& userName, const std::string & msg)
{
ConnectionSession & session = rcfSession.
getSessionObject<ConnectionSession>(
true);
++session.mCallsMade;
ServerSessionPtr sessionPtr = server.
getServerObject<ServerSession>(userName, 60 * 1000);
sessionPtr->mUserName = userName;
++sessionPtr->mCallsMade;
std::cout << std::endl;
std::cout << "I_PrintService service (" << userName << "): " << msg << std::endl;
std::cout << "Print() calls made on this connection: " << session.mCallsMade << std::endl;
std::cout << "Print() calls made by this user: " << sessionPtr->mCallsMade << std::endl;
}
};
int main()
{
try
{
PrintService printService;
server.
bind<I_PrintService>(printService);
std::cout << "Press Enter to exit..." << std::endl;
std::cin.get();
}
{
}
return 0;
}
Server-side Session Objects - Client
This sample demonstrates a client calling a server and maintaining a connection session and a server session on the server.
#include <iostream>
#include <RCF/RCF.hpp>
RCF_BEGIN(I_PrintService, "I_PrintService")
RCF_METHOD_V2(void, Print, const std::string&, const std::string &)
RCF_END(I_PrintService)
int main()
{
try
{
std::string userName = "Joe Bloggs";
for ( int i = 0; i < 3; ++i )
{
for ( int i = 0; i < 5; ++i )
{
client.Print(userName, "Hello World");
}
}
}
{
}
return 0;
}