Remote Call Framework 3.4
Proxy endpoints

Proxy Endpoint Server

This sample demonstrates a server exposing a proxy endpoint, allowing clients to connect to a destination server.

#include <iostream>
#include <RCF/RCF.hpp>
#include <RCF/ProxyEndpoint.hpp>
// Define RCF interface.
RCF_BEGIN(I_PrintService, "I_PrintService")
RCF_METHOD_V1(void, Print, const std::string &)
RCF_END(I_PrintService)
int main()
{
try
{
RCF::RcfInit rcfInit;
// Configure proxy endpoint server.
RCF::RcfServer server(RCF::TcpEndpoint("127.0.0.1", 50001));
server.setThreadPool(RCF::ThreadPoolPtr(new RCF::ThreadPool(1, 10)));
server.start();
// Wait for destination server to come on line.
std::string printServerName = "RoamingPrintSvr";
bool done = false;
while ( !done )
{
std::vector<std::string> proxyEndpoints;
server.enumerateProxyEndpoints(proxyEndpoints);
for ( auto proxyEndpoint : proxyEndpoints )
{
if ( proxyEndpoint == printServerName )
{
{
std::cout << "In-process connection to proxy endpoint '" << printServerName << "'.";
RcfClient<I_PrintService> client(RCF::ProxyEndpoint(server, printServerName));
client.Print("Calling I_PrintService through a proxy endpoint");
}
{
std::cout << "Out-of-process connection to proxy endpoint '" << printServerName << "'.";
RcfClient<I_PrintService> client(RCF::ProxyEndpoint(RCF::TcpEndpoint("127.0.0.1", 50001), printServerName));
client.Print("Calling I_PrintService through a proxy endpoint");
}
done = true;
}
}
}
}
catch ( const RCF::Exception & e )
{
std::cout << "Error: " << e.getErrorMessage() << std::endl;
}
return 0;
}

Destination Server

This sample demonstrates a destination server receiving calls through a proxy endpoint.

#include <iostream>
#include <RCF/RCF.hpp>
#include <RCF/ProxyEndpoint.hpp>
// Define RCF interface.
RCF_BEGIN(I_PrintService, "I_PrintService")
RCF_METHOD_V1(void, Print, const std::string &)
RCF_END(I_PrintService)
// Server implementation of the I_PrintService RCF interface.
class PrintService
{
public:
void Print(const std::string & s)
{
std::cout << "I_PrintService service: " << s << std::endl;
}
};
int main()
{
try
{
RCF::RcfInit rcfInit;
// Configure destination server, using the network address of the proxy endpoint server.
std::string printServerName = "RoamingPrintSvr";
RCF::RcfServer server( RCF::ProxyEndpoint( RCF::TcpEndpoint("127.0.0.1", 50001), printServerName) );
PrintService printService;
server.bind<I_PrintService>(printService);
server.start();
// Destination server can now receive calls through the proxy endpoint server.
// ...
std::cout << "Press Enter to exit..." << std::endl;
std::cin.get();
}
catch ( const RCF::Exception & e )
{
std::cout << "Error: " << e.getErrorMessage() << std::endl;
}
return 0;
}