cpp-msgpack-rpc
0.2.0
An RPC library implementing MessagePack RPC.
Toggle main menu visibility
Loading...
Searching...
No Matches
simple_client.cpp
Example of a simple client.
/*
* Copyright 2024 MusicScience37 (Kenta Kabashima)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cassert>
#include <iostream>
#include "
msgpack_rpc/clients/client.h
"
#include "
msgpack_rpc/clients/client_builder.h
"
int
main() {
// Create a client.
msgpack_rpc::clients::Client
client =
msgpack_rpc::clients::ClientBuilder
()
// Specify the URI of the server to connect to.
.
connect_to
(
"tcp://localhost:7136"
)
// build() creates a client and starts processing of the client.
.
build
();
// Call a method in the server.
// Specify the result type in the template parameter.
const
int
result = client.
call
<
int
>(
"add"
, 2, 3);
std::cout <<
"Result: "
<< result << std::endl;
// NOLINT
assert(result == 5);
// Stop the client by destructing the client.
return
0;
}
msgpack_rpc::clients::ClientBuilder
Class of builders of clients.
Definition
client_builder.h:40
msgpack_rpc::clients::ClientBuilder::build
Client build()
Build a client.
Definition
client_builder.h:111
msgpack_rpc::clients::ClientBuilder::connect_to
ClientBuilder & connect_to(addresses::URI uri)
Add a URI to connect to.
Definition
client_builder.h:78
msgpack_rpc::clients::Client
Class of clients.
Definition
client.h:39
msgpack_rpc::clients::Client::call
std::decay_t< Result > call(messages::MethodNameView method_name, const Parameters &... parameters)
Synchronously call a method.
Definition
client.h:89
client.h
Definition of Client class.
client_builder.h
Definition of ClientBuilder class.
Generated on
for cpp-msgpack-rpc by
1.18.0