Skip to content

Lightweight websocket implement for stream transmission.

License

Notifications You must be signed in to change notification settings

zephyrchien/lightws

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lightws

Lightws Lightws Released API docs crates.io

Lightweight websocket implement for stream transmission.

Features

  • Avoid heap allocation.
  • Avoid buffering frame payload.
  • Use vectored-io if available.
  • Transparent Read/Write over the underlying IO source.

High-level API

[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?;
}

Low-level API

[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();
}

About

Lightweight websocket implement for stream transmission.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages