Crates.io | lightws |
lib.rs | lightws |
version | |
source | src |
created_at | 2022-03-17 16:17:46.357606 |
updated_at | 2024-10-14 05:20:21.502466 |
description | Lightweight websocket implement for stream transmission. |
homepage | |
repository | https://github.com/zephyrchien/lightws |
max_upload_size | |
id | 551889 |
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 |
Lightweight websocket implement for stream transmission.
[role, endpoint, stream]
Std:
{
// handshake
let stream = Endpoint<TcpStream, Client>::connect(tcp, buf, host, path)?;
// read some data
stream.read(&mut buf)?;
// write some data
stream.write(&buf)?;
}
Async:
{
// handshake
let stream = Endpoint<TcpStream, Client>::connect_async(tcp, buf, host, path).await?;
// read some data
stream.read(&mut buf).await?;
// write some data
stream.write(&buf).await?;
}
[frame, handshake]
Frame:
{
// encode a frame head
let head = FrameHead::new(...);
let offset = unsafe {
head.encode_unchecked(&mut buf);
};
// decode a frame head
let (head, offset) = FrameHead::decode(&buf).unwrap();
}
Handshake:
{
// make a client handshake request
let request = Request::new(b"/ws", b"example.com", "sec-key..");
let offset = request.encode(&mut buf).unwrap();
// parse a server handshake response
let mut custom_headers = HttpHeader::new_storage();
let mut response = Response::new_storage(&mut custom_headers);
let offset = response.decode(&buf).unwrap();
}