()
| 9 | |
| 10 | #[tokio::main] |
| 11 | async fn main() -> anyhow::Result<()> { |
| 12 | // In Rust, anything that will block is awaited. For instance, if we're going |
| 13 | // to connect to a remote server, that might take some time due to the network |
| 14 | // connection quality, or other issues. To deal with that, we use async/await. |
| 15 | // |
| 16 | // For now, you can ignore the API calls here, since we're just talking about |
| 17 | // how our API works in general. Setting up a connection is discussed more in |
| 18 | // the Connecting section of this document. |
| 19 | let connector = ButtplugRemoteClientConnector::< |
| 20 | ButtplugWebsocketClientTransport, |
| 21 | ButtplugClientJSONSerializer, |
| 22 | >::new(ButtplugWebsocketClientTransport::new_insecure_connector( |
| 23 | "ws://127.0.0.1:12345", |
| 24 | )); |
| 25 | |
| 26 | // For Request/Response messages, we'll use our Connect API. Connecting to a |
| 27 | // server requires the client and server to send information back and forth, |
| 28 | // so we'll await that while those (possibly somewhat slow, depending on if |
| 29 | // network is being used and other factors) transfers happen. |
| 30 | let client = ButtplugClient::new("Example Client"); |
| 31 | client |
| 32 | .connect(connector) |
| 33 | .await |
| 34 | .expect("Can't connect to Buttplug Server, exiting!"); |
| 35 | |
| 36 | let mut event_stream = client.event_stream(); |
| 37 | // As an example of event messages, we'll assume the server might |
| 38 | // send the client notifications about new devices that it has found. |
| 39 | // The client will let us know about this via events. |
| 40 | while let Some(event) = event_stream.next().await { |
| 41 | if let ButtplugClientEvent::DeviceAdded(device) = event { |
| 42 | println!("Device {} connected", device.name()); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | Ok(()) |
| 47 | } |
nothing calls this directly
no test coverage detected