Skip to main content

wscat_rs/
lib.rs

1//! # wscat-rs
2//! 
3//! A WebSocket client for the command line, similar to `netcat` but for WebSocket connections.
4//! 
5//! This crate provides a CLI tool that can connect to WebSocket servers (both `ws://` and `wss://`),
6//! send and receive messages interactively, and optionally use slash commands for WebSocket-specific
7//! operations like ping/pong and connection closing.
8//! 
9//! ## Features
10//! 
11//! - Connect to WebSocket servers using `ws://` or `wss://` protocols
12//! - Skip TLS certificate validation with `--insecure` flag
13//! - Send custom headers with the initial WebSocket handshake
14//! - Specify WebSocket subprotocols
15//! - Interactive slash commands (`/ping`, `/pong`, `/close`)
16//! - TTY-aware output formatting (prefixes messages with `<` when stdout is a terminal)
17//! - Verbose mode to see request details
18//! - Dry-run mode to preview the connection without actually connecting
19//! 
20//! ## Usage
21//! 
22//! Basic connection:
23//! ```bash
24//! wscat-rs -c wss://echo.websocket.org
25//! ```
26//! 
27//! With custom headers and subprotocol:
28//! ```bash
29//! wscat-rs -c wss://example.com --header "Authorization: Bearer token" --protocol graphql-ws
30//! ```
31//! 
32//! With slash commands enabled:
33//! ```bash
34//! wscat-rs -c wss://example.com --slash
35//! # Then in the session:
36//! # /ping hello
37//! # /close 1000 goodbye
38//! ```
39//! 
40//! ## Library Usage
41//! 
42//! While primarily designed as a CLI tool, the slash command parsing functionality
43//! is exposed for library use:
44//! 
45//! ```rust
46//! use wscat_rs::parse_slash_command;
47//! use tokio_tungstenite::tungstenite::Message;
48//! 
49//! if let Some(msg) = parse_slash_command("/ping hello") {
50//!     match msg {
51//!         Message::Ping(data) => println!("Ping with data: {:?}", data),
52//!         _ => {}
53//!     }
54//! }
55//! ```
56
57pub mod slash;
58
59pub use slash::parse_slash_command;