cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
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>
int main() {
// Create a client.
// 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;
}
Class of builders of clients.
ClientBuilder & connect_to(addresses::URI uri)
Add a URI to connect to.
Class of clients.
Definition client.h:39
std::decay_t< Result > call(messages::MethodNameView method_name, const Parameters &... parameters)
Synchronously call a method.
Definition client.h:89
Definition of Client class.
Definition of ClientBuilder class.