A C++ client implementation for the Buttplug intimate hardware control protocol.
This library provides a C++ client for the Buttplug Server, allowing developers to connect to and control various intimate hardware devices. The implementation supports C++11 and higher with minimal external dependencies.
Key features:
- WebSocket-based communication with Buttplug servers
- Thread-safe device control
- Support for various device commands (vibration, linear, rotation)
- Support for sensor reading and subscription
- Built-in logging capabilities
The library has the following dependencies:
- IXWebSocket - WebSocket client
- nlohmann/json - JSON parsing
- C++11 compatible compiler
- Install the required dependencies:
# Install build tools
sudo apt-get update
sudo apt-get install build-essential cmake git
# Install nlohmann/json (via package manager if available)
sudo apt-get install nlohmann-json3-dev
# Or manually (if not available in package manager)
git clone https://github.com/nlohmann/json.git
cd json
mkdir build && cd build
cmake ..
make
sudo make install
cd ../..- Build IXWebSocket:
git clone https://github.com/machinezone/IXWebSocket.git
cd IXWebSocket
mkdir build && cd build
cmake ..
make
sudo make install
cd ../..- Clone and build this repository:
git clone https://github.com/dumbowumbo/buttplugCpp
cd buttplugCpp
mkdir build && cd build
cmake ..
make- Install the library system-wide (optional):
sudo make installThis will install:
- Library files to
/usr/local/lib(or as configured) - Headers to
/usr/local/include/buttplug - CMake configuration files for dependent projects
- To uninstall the library (if needed):
sudo make uninstall-
Install Visual Studio with C++ development tools
-
Install vcpkg:
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
bootstrap-vcpkg.bat- Install dependencies via vcpkg:
vcpkg install nlohmann-json:x64-windows
vcpkg install ixwebsocket:x64-windows
vcpkg integrate install- Clone this repository and open it in Visual Studio:
git clone https://github.com/dumbowumbo/buttplugCpp
cd buttplugCpp- Create a new CMake project in Visual Studio, or run the following from Developer Command Prompt:
mkdir build
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=[path\to\vcpkg]\scripts\buildsystems\vcpkg.cmake- Build the project:
cmake --build . --config Release- Install the library (optional, run as Administrator):
cmake --install . --config ReleaseThis will install:
- Library files to the system library directory
- Headers to the system include directory
- CMake configuration files for dependent projects
- To uninstall the library (if needed, run as Administrator):
cmake -P cmake_uninstall.cmake#include <buttplug/buttplugclient.h>
#include <iostream>
#include <thread>
#include <chrono>
// Callback for handling device messages
void messageHandler(const mhl::Messages& msg) {
if (msg.messageType == mhl::MessageTypes::DeviceAdded) {
std::cout << "New device added: " << msg.deviceAdded.device.DeviceName << std::endl;
}
}
int main() {
// Create client connection to a buttplug server at localhost:12345
Client client("ws://localhost", 12345);
// Connect to the server
client.connect(messageHandler);
// Start scanning for devices
client.startScan();
// Wait for devices to connect
std::this_thread::sleep_for(std::chrono::seconds(5));
// Get list of connected devices
auto devices = client.getDevices();
if (!devices.empty()) {
// Control the first device (simple vibration at 50% power)
client.sendScalar(devices[0], 0.5);
std::this_thread::sleep_for(std::chrono::seconds(3));
// Stop the device
client.stopDevice(devices[0]);
}
return 0;
}After installing the library, you can easily use it in your CMake projects:
find_package(ButtplugClient REQUIRED)
add_executable(my_app main.cpp)
target_link_libraries(my_app PRIVATE ButtplugClient::buttplugclient)The Buttplug protocol documentation is available at:
Contributions are welcome! Please feel free to submit a Pull Request.