#include #include #include #include #include "remote/server/Server.hpp" #include "TestDatabase.hpp" // Ugly class for testing purposes class TestServer { public: TestServer(boost::asio::ip::tcp::endpoint endpoint) : _db(TestDatabase::create()), _server(_ioService, endpoint, _db->getPath()), _thread( boost::bind(&TestServer::threadEntry, this)) { _server.run(); } void stop() { _ioService.stop(); _thread.join(); } private: void threadEntry(void) { _ioService.run(); } boost::asio::io_service _ioService; std::unique_ptr _db; Remote::Server::Server _server; std::thread _thread; }; class TestClient { public: TestClient(boost::asio::ip::tcp::endpoint endpoint) :_socket(_ioService) { _socket.connect(endpoint); } private: boost::asio::io_service _ioService; boost::asio::ip::tcp::socket _socket; }; int main(int argc, char* argv[]) { try { // Runs in its own thread // Listen on any TestServer testServer( boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 5080)); // Client // connect to loopback TestClient client( boost::asio::ip::tcp::endpoint( boost::asio::ip::address_v4::loopback(), 5080)); // TODO get some data testServer.stop(); } catch(std::exception& e) { std::cerr << "Caught exception " << e.what() << std::endl; return EXIT_FAILURE; } return EXIT_SUCCESS; }