Crates.io | websocket-std |
lib.rs | websocket-std |
version | 0.0.6 |
source | src |
created_at | 2023-05-10 16:00:48.826321 |
updated_at | 2024-02-15 20:38:49.655551 |
description | Websocket implementation using std support, focus on microcontrollers and interoperability with other languages like C through the ffi. |
homepage | https://github.com/alekay-software/websocket-std |
repository | https://github.com/alekay-software/websocket-std |
max_upload_size | |
id | 861422 |
size | 77,437 |
This is a WebSocket implementation in Rust that utilizes the standard library. Its goal is to function on low-resource devices such as microcontrollers, although it can also be applied in high-performance computer programs. I started the project for three main reasons:
The project is currently in beta phase, and while it is functional, further work is needed for the final version. Since I am a sole developer and cannot dedicate as much time as I would like, I have decided to publish it for those who want to try it out and contribute to the project CONTRIBUTING.md.
You can use the library in the following ways:
esp-rs
with std
support. Check out the esp-rs docs for more information.Feel free to explore the project and contribute! 🚀
In the ffi/
folder you will find the websocket-std.h
header and a compiled static library for the xtensa architecture of the esp32 microcontroller from espressif.
You can use this static library in your esp idf and arduino projects for esp32. Check ffi/xtensa-esp32-idf for more information.
The examples folder contains various examples of how to use websocket-std
.
The sync client manage an internal event loop, when you call a function to perform a websocket operation (init
, send
, ...)
it will be queued and as soon as you call the event_loop
function it will perform one input (something was received)
and one output (something to send to server) operations in one execution.
You can also use threads
to work with the library. Check examples for more information.
I'm planning also to introduce in the library a sync server
following the same philosophy as the sync client.
ESP32
using esp-rs with std supportESP32
using arduino
framework in a PlatformIO
project. (Should also work with esp-idf proyects).Since is my first rust big project I started using the following tools for testing and code coveragera, but I would like to define another way of doing that because the test coverage reports are not the bests. I'm open to hear better ways of doing testing in rust.
cargo test
grcov
toolrustup component add llvm-tools-preview
export RUSTFLAGS="-Cinstrument-coverage"
export LLVM_PROFILE_FILE="websocket-std-%p-%m.profraw"
cargo install grcov
Ensure that there isn't compilation or test errors.
cargo build
OK
cargo test
grcov . --binary-path ./target/debug/deps/ -s . -t html --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o target/coverage --excl-line grcov-excl-line
The report will be generated at target/coverage/
, open index.html
with a browser to see the results.
Since the library doesn't have a way to create websocket servers, here you will find an echo server example in python to test the client.
import asyncio
from websockets.server import serve
HOST = "0.0.0.0"
PORT = 3000
protocol = ["superchat", "app", "chat"]
async def echo(websocket):
async for message in websocket:
if websocket.open:
await websocket.send(message)
async def main():
async with serve(echo, HOST, PORT, subprotocols=protocol):
print(f"Websocket server running on: {HOST}:{PORT}")
await asyncio.Future() # run forever
asyncio.run(main())