pub struct Client { /* private fields */ }
Expand description
The base kRPC client type.
§Connecting to the kRPC server
Call new
to establish a connection with the
kRPC server.
use krpc_client::Client;
let client = Client::new("Test KRPC", "127.0.0.1", 50000, 50001);
§Using RPC services
Pass or clone the client instance returned by
Client::new
to any RPC service in
krpc_client::services::*
.
use krpc_client::{services::space_center::SpaceCenter, Client};
let space_center = SpaceCenter::new(client);
// Then call procedures with the created service.
println!("Hello, {}!", space_center.get_active_vessel()?.get_name()?);
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(
name: &str,
ip_addr: &str,
rpc_port: u16,
stream_port: u16,
) -> Result<Arc<Self>, RpcError>
pub fn new( name: &str, ip_addr: &str, rpc_port: u16, stream_port: u16, ) -> Result<Arc<Self>, RpcError>
Constructs a new Client
.
§Examples
use krpc_client::Client;
let client = Client::new("Test KRPC", "127.0.0.1", 50000, 50001);
Examples found in repository?
examples/streams.rs (line 8)
7fn main() -> Result<(), Box<dyn Error>> {
8 let client = Client::new("kRPC TEST", "127.0.0.1", 50000, 50001)?;
9
10 let space_center = SpaceCenter::new(client.clone());
11
12 // Set up a stream.
13 let ut_stream = space_center.get_ut_stream()?;
14 ut_stream.set_rate(1f32)?;
15
16 // Wait for updates, and print the current value.
17 for _ in 0..10 {
18 ut_stream.wait();
19 println!("It's {} o'clock", ut_stream.get()?);
20 }
21
22 Ok(())
23}
More examples
examples/client.rs (line 8)
7fn main() -> Result<(), Box<dyn Error>> {
8 let client = Client::new("kRPC TEST", "127.0.0.1", 50000, 50001).unwrap();
9
10 let sc = SpaceCenter::new(client.clone());
11
12 // Check out our vessel.
13 let ship = sc.get_active_vessel()?;
14
15 // Greet the crew.
16 match ship.get_crew()?.first() {
17 Some(kerbal) => println!(
18 "Hello, {}. Welcome to {}",
19 kerbal.get_name()?,
20 ship.get_name()?
21 ),
22 None => println!("{} is unkerbaled!", ship.get_name()?),
23 };
24
25 Ok(())
26}
Auto Trait Implementations§
impl !Freeze for Client
impl RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more