TCP Server
This sample demonstrates a simple TCP server.
#include <iostream>
#include <RCF/RCF.hpp>
RCF_BEGIN(I_PrintService, "I_PrintService")
RCF_METHOD_V1(void, Print, const std::string &)
RCF_END(I_PrintService)
class PrintService
{
public:
void Print(const std::string & s)
{
std::cout << "I_PrintService service: " << s << 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;
}
TCP Client
This sample demonstrates a TCP client. It is intended to be run against the TCP server above.
#include <iostream>
#include <RCF/RCF.hpp>
RCF_BEGIN(I_PrintService, "I_PrintService")
RCF_METHOD_V1(void, Print, const std::string &)
RCF_END(I_PrintService)
int main()
{
try
{
std::cout << "Calling the I_PrintService Print() method." << std::endl;
client.Print("Hello World");
}
{
}
return 0;
}
Combined TCP Server and Client
This sample demonstrates a simple TCP client and server, communicating within a single process.
#include <iostream>
#include <RCF/RCF.hpp>
RCF_BEGIN(I_PrintService, "I_PrintService")
RCF_METHOD_V1(void, Print, const std::string &)
RCF_END(I_PrintService)
class PrintService
{
public:
void Print(const std::string & s)
{
std::cout << "I_PrintService service: " << s << std::endl;
}
};
int main()
{
try
{
PrintService printService;
server.
bind<I_PrintService>(printService);
std::cout << "Calling the I_PrintService Print() method." << std::endl;
client.Print("Hello World");
}
{
}
return 0;
}