Files
rest_rpc/test_client/main.cpp
T
2018-12-20 12:20:14 +08:00

55 lines
1.1 KiB
C++

#include <iostream>
#include "test_client.hpp"
#include "../codec.h"
using namespace rest_rpc;
using namespace rest_rpc::rpc_service;
void test_add() {
try{
boost::asio::io_service io_service;
test_client client(io_service);
client.connect("127.0.0.1", "9000");
auto result = client.call<int>("add", 1, 2);
std::cout << result << std::endl;
}
catch (const std::exception& e){
std::cout << e.what() << std::endl;
}
}
void test_translate() {
try {
boost::asio::io_service io_service;
test_client client(io_service);
client.connect("127.0.0.1", "9000");
auto result = client.call<std::string>("translate", "hello");
std::cout << result << std::endl;
}
catch (const std::exception& e) {
std::cout << e.what() << std::endl;
}
}
void test_hello() {
try {
boost::asio::io_service io_service;
test_client client(io_service);
client.connect("127.0.0.1", "9000");
client.call("hello", "purecpp");
}
catch (const std::exception& e) {
std::cout << e.what() << std::endl;
}
}
int main() {
test_hello();
test_add();
test_translate();
return 0;
}