Crates.io | typed-websocket |
lib.rs | typed-websocket |
version | |
source | src |
created_at | 2024-11-22 07:45:20.886104 |
updated_at | 2024-11-22 07:45:20.886104 |
description | simple wrapper on top of websocket stream that enforces type |
homepage | |
repository | https://github.com/kanekoshoyu/kucoin_arbitrage |
max_upload_size | |
id | 1457160 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | 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 |
simple wrapper on top of websocket stream that enforces type
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
use tokio_tungstenite::connect_async;
use url::Url;
let url = Url::parse("wss://example.com/socket")?;
let (stream, _) = connect_async(url).await?;
// Create a TypedWebSocketStream with specific input/output types
let mut ws: TypedWebSocketStream<_, RequestMessage, ResponseMessage> = TypedWebSocketStream::new(stream);
// Send a message
let outgoing = RequestMessage::new();
ws.send(outgoing).await?;
// Receive a message
match ws.receive().await {
Ok(incoming) => println!("Received: {:?}", incoming),
Err(e) => eprintln!("Error receiving message: {}", e),
}
// Close the connection
ws.close().await?;
Ok(())
}
// Define input and output message types
#[derive(Serialize, Debug)]
struct RequestMessage {
command: String,
data: String,
}
#[derive(Deserialize, Debug)]
struct ResponseMessage {
response: String,
status: u16,
}