Server.cpp
Code: Select all
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <RCF/RCF.hpp>
#include "MyService.hpp"
class Session
{
public:
Session()
{
std::cout << "+ Session #" << this << std::endl;
}
~Session()
{
std::cout << "- Session #" << this << std::endl;
}
};
class MyServiceImpl
{
public:
// Reverses the order of strings in the vector.
void reverse(std::vector<std::string> &v)
{
RCF::getCurrentRcfSession().getSessionObject<Session>(true);
std::cout << "Reversing a vector of strings...\n";
std::vector<std::string> w;
std::copy(v.rbegin(), v.rend(), std::back_inserter(w));
v.swap(w);
}
};
int main()
{
RCF::RcfInitDeinit rcfInit;
// Start a TCP server on port 50001, and expose MyServiceImpl.
MyServiceImpl myServiceImpl;
RCF::RcfServer server( RCF::TcpEndpoint("0.0.0.0", 50001) );
server.bind<MyService>(myServiceImpl);
server.start();
std::cout << "Press Enter to exit..." << std::endl;
std::cin.get();
return 0;
}
Code: Select all
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include "MyService.hpp"
#include <RCF/RCF.hpp>
int main()
{
RCF::RcfInitDeinit rcfInit;
try
{
// Setup a vector of strings.
std::vector<std::string> v;
v.push_back("one");
v.push_back("two");
v.push_back("three");
// Print them out.
std::cout << "Before:\n";
std::copy(
v.begin(),
v.end(),
std::ostream_iterator<std::string>(std::cout, "\n"));
// Make the call.
RcfClient<MyService> Client( RCF::TcpEndpoint("server", 50001) ); // put server address here
Client.reverse(v);
// Print them out again. This time they are in reverse order.
std::cout << "\nAfter:\n";
std::copy(
v.begin(),
v.end(),
std::ostream_iterator<std::string>(std::cout, "\n"));
std::cout << "Press Enter to exit..." << std::endl;
std::cin.get();
}
catch(const RCF::Exception & e)
{
std::cout << "Caught exception:\n";
std::cout << e.getError().getErrorString() << std::endl;
return 1;
}
return 0;
}
1. power off of client machine (without OS shut down, just instant power off)
2. disconnection of physycal network
3. turning off wi-fi collection
etc... (try these thing instead of pressing Enter in client)
In such cases Session object is not destroyed (see server's output) and connection stays established:
Code: Select all
C:\>netstat -n
...
TCP 192.168.64.129:50001 192.168.64.128:1040 ESTABLISHED