Crates.io | stream-tungstenite |
lib.rs | stream-tungstenite |
version | 0.4.0 |
source | src |
created_at | 2024-10-23 08:46:57.113438 |
updated_at | 2024-11-21 09:47:54.602163 |
description | A streaming implementation of the Tungstenite WebSocket protocol |
homepage | |
repository | |
max_upload_size | |
id | 1419843 |
size | 38,090 |
stream-tungstenite
is a Rust library designed to facilitate the management of WebSocket connections with automatic reconnection capabilities. It provides a robust framework for handling WebSocket communication, including error handling, event listening, and customizable reconnection strategies.
WebSocket connections can be unstable due to network issues, server downtime, or other unforeseen circumstances. This library addresses the following challenges:
Here’s a simple example of how to use stream-tungstenite
to establish a WebSocket connection and handle messages:
use stream_tungstenite::{ReconnectT, ReconnectOptions};
use tokio_tungstenite::tungstenite::Message;
#[tokio::main]
async fn main() {
let options = ReconnectOptions::default();
let reconnect = ReconnectT::new("wss://example.com/socket", Some(options));
// Start the connection
reconnect.run().await;
}
In this example, a new ReconnectT
instance is created with a specified WebSocket URL and default options. The run
method initiates the connection and handles reconnections automatically.
To include stream-tungstenite
in your project, add the following to your Cargo.toml
:
[dependencies]
stream-tungstenite = "0.4.0"
Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.
This project is licensed under the Apache License Version 2.0. See the LICENSE file for more details.