Crates.io | websocket_toolkit |
lib.rs | websocket_toolkit |
version | |
source | src |
created_at | 2024-11-24 03:57:21.642355 |
updated_at | 2024-11-24 03:57:21.642355 |
description | A WebSocket toolkit for Rust, enabling efficient real-time communication with flexible reconnection and message handling capabilities. |
homepage | https://github.com/SUMANTH571/Websocket-Toolkit |
repository | https://github.com/SUMANTH571/Websocket-Toolkit |
max_upload_size | |
id | 1458950 |
Cargo.toml error: | TOML parse error at line 22, column 1 | 22 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
WebSocket Toolkit
is a Rust crate designed to simplify WebSocket communication for real-time web applications. It provides the foundational structure to manage WebSocket connections, implement flexible reconnection strategies, handle multiple message formats with configurable serialization/deserialization, and maintain robust keep-alive mechanisms.
This release serves as the initial framework for the project, setting up the core modules, dependency management, and basic features. Future versions will expand on this with more advanced functionality.
This release builds upon the initial framework by defining all public API functions, improving internal dependencies, and ensuring modularity. The project is now better structured to prepare for full functionality and documentation in future releases.
This release finalizes all core functionalities:
The final release includes all features from previous releases and adds:
cargo doc --open
, all modules, functions, and structs are thoroughly documented.The project follows a modular design where each core feature (connection management, reconnection logic, message handling, keep-alive mechanism) is defined in its own module. Here's a breakdown of the project’s main components:
connection.rs
:
WebSocketClient
struct, which provides basic connection setup and connection management.reconnection.rs
:
ReconnectStrategy
struct handles the number of retry attempts and delay configurations.messages.rs
:
serde
library.keep_alive.rs
:
tokio::time
for periodic ping/pong frames, keeping the connection active.controller.rs
:
lib.rs
:
main.rs
:
Provides an example executable demonstrating how to use the library.
Creates a WebSocketClient
, connects to a WebSocket server, and performs messaging tasks.
Asynchronous, Non-Blocking Connection Management:
tokio-tungstenite
crate along with Rust's async/await syntax to create efficient, non-blocking WebSocket connections.Reconnection Logic:
ReconnectStrategy
provides customizable reconnection behavior with retries and exponential backoff.Message Handling:
serde
. The messages
module handles serialization and deserialization, with flexibility for future formats.Keep-Alive Mechanism:
Periodically sends ping/pong frames to ensure that WebSocket connections remain active. The interval for pings is configurable.
tokio
: Asynchronous runtime for non-blocking operations.tokio-tungstenite
: WebSocket client/server library.serde
: Serialization/deserialization framework.serde_json
: JSON support.serde_cbor
: CBOR support.log
: Logging framework.cargo-fuzz
: Fuzz testing framework for Rust.
1. Install Rust (Stable and Nightly Toolchains):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup install stable
rustup install nightly
rustup default stable
2. Install LLVM and Clang:
sudo apt-get update
sudo apt-get install -y clang llvm libclang-dev
brew install llvm
3. Install Cargo-Fuzz:
cargo install cargo-fuzz
Steps to use the crate: 1. Clone the repository:
git clone https://github.com/SUMANTH571/Websocket-Toolkit.git
cd websocket_toolkit
2. Build the project:
cargo build
3. Run tests:
cargo test -- --nocapture
Note: If running locally, replace ws://node_server:9001 with ws://127.0.0.1:9001 in the tests.
4. Run the example:
cargo run --example simple_websocket
1. Install cargo-fuzz:
cargo install cargo-fuzz
2. Run fuzz testing:
cargo fuzz run websocket_fuzz
Note for Windows Users: Fuzzing with cargo-fuzz may not work due to LLVM dependencies. Use a Linux VM, WSL, or the provided Docker environment for fuzzing.
1. Docker Compose File (docker-compose.yml): Includes services for both the Rust application and a Node.js WebSocket server.
2. Rust Dockerfile (Dockerfile.rust): Installs Rust, cargo-fuzz, LLVM, and other dependencies.
3. Node.js Dockerfile (Dockerfile.node): Sets up a Node.js WebSocket server with required dependencies (ws and cbor).
Verify the crate’s documentation builds correctly.
cargo doc --open
This step requires API Token generated on crate.io accounts page to authenticate.
cargo login
Verify if the crate is ready to be published by running the following commands:
cargo check
cargo build
cargo test -- --nocapture
Once all verifications are complete, publish the crate:
cargo publish