Skip to main content

Websocket Connectors

The first thing to do when writing a Buttplug application is figuring out how to talk to a Buttplug Server. For sake of simplicity, we'll cover the most common option in this part of the manual, with other solutions covered in the cookbook section.

In the websocket case, you'll allow the user to connect to a Buttplug server they're running on their system, outside of your application (this usually means the user will be running Intiface Central or Intiface Engine). In almost all cases, your app will connect via websockets, most likely provided by the Buttplug Client implementation you are using.

For using Websocket servers, you'll need to provide the user a way to pass in the server address, then you just create the connector object using that address.

The Accidental Standard Port of 12345

When Buttplug's first public server came out in 2017, it used port 12345 as a test value. This stuck with the system, so now most applications that use Intiface or Buttplug use port 12345 for connection by default. Some client applications have gone as far as to hardcore the value, but this is not recommended.

This can sometimes be an issue for users running certain software that collides with the port. We have some recommended fixes on our forums.

use buttplug::{
client::ButtplugClient,
core::{
connector::{ButtplugRemoteConnector, ButtplugWebsocketClientTransport, new_json_ws_client_connector},
message::serializer::ButtplugClientJSONSerializer,
},
};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
// To create a Websocket Connector, you need the websocket address and some generics fuckery.
let connector = new_json_ws_client_connector("ws://192.168.123.103:12345/buttplug");

let client = ButtplugClient::new("Example Client");
client.connect(connector).await?;

Ok(())
}