From 65c5c3b7e74ee7d7d1a2ebba70171288d147bd9d Mon Sep 17 00:00:00 2001 From: qicosmos Date: Thu, 10 Jan 2019 06:03:42 +0800 Subject: [PATCH] add another example --- main.cpp | 5 +++++ test_client/main.cpp | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/main.cpp b/main.cpp index 306e499..e353ccb 100644 --- a/main.cpp +++ b/main.cpp @@ -30,6 +30,10 @@ std::string get_person_name(connection* conn, const person& p) { return p.name; } +person get_person(connection* conn) { + return { 1, "tom", 20 }; +} + int main() { rpc_server server(9000, 4); @@ -38,6 +42,7 @@ int main() { server.register_handler("translate", translate); server.register_handler("hello", hello); server.register_handler("get_person_name", get_person_name); + server.register_handler("get_person", get_person); server.run(); diff --git a/test_client/main.cpp b/test_client/main.cpp index f499392..8a4c74a 100644 --- a/test_client/main.cpp +++ b/test_client/main.cpp @@ -69,7 +69,22 @@ void test_get_person_name() { } } +void test_get_person() { + try { + boost::asio::io_service io_service; + test_client client(io_service); + client.connect("127.0.0.1", "9000"); + + auto result = client.call("get_person"); + std::cout << result.name << std::endl; + } + catch (const std::exception& e) { + std::cout << e.what() << std::endl; + } +} + int main() { + test_get_person(); test_get_person_name(); test_hello(); test_add();