Crates.io | webrocket |
lib.rs | webrocket |
version | 0.1.0 |
source | src |
created_at | 2023-01-26 19:31:36.654862 |
updated_at | 2023-01-26 19:31:36.654862 |
description | A closure focused WebSocket server implementation. |
homepage | |
repository | https://github.com/otsmr/websocket |
max_upload_size | |
id | 768811 |
size | 63,721 |
WebRocket 🚀 is a WebSocket server library programmed in Rust from scratch (including SHA-1 and Base64).
Note: This project was created to learn Rust, so major changes may still occur.
To add a library release version from crates.io to a Cargo project, add this to the 'dependencies' section of your Cargo.toml:
Please do not use in production yet.
webrocket = "0.1.0"
Since I am a big closure fan, many functions are offered as clousures, like on_connection or on_message.
To start an echo server it only needs the following code:
let mut ws = WebSocket::bind("0.0.0.0:3000").await?;
ws.on_connection(|wsc| {
println!("New connection");
wsc.on_message(|wsc, msg| {
println!("New message: {}", msg);
wsc.send_message(msg);
});
wsc.on_close(|_, code, reason| {
println!("Connection closed ({:?}) with '{}' as reason.", code, reason);
});
});
ws.listen().await;
The server implementation was tested with the Autobahn|Testsuite as follows:
$ RUST_LOG=debug cargo run --bin wsserver_autobahn
$ docker run -it --rm --net=host \
-v "${PWD}/tests:/config" \
-v "${PWD}/tests/reports:/reports" \
--name fuzzingclient \
crossbario/autobahn-testsuite \
wstest -m fuzzingclient --spec /config/fuzzingclient.json
There are also tests in the code, which can be started with cargo test
.
TLS v1.3
Before I wrote the WebSocket in Rust, I first programmed it in C++ to teach
myself C++. I now use this implementation, which is in the fun-with-cpp
branch,
as a playground for e.g. fuzzing.
brew install cmake
check compile options in flags.h (!)
#define COMPILE_FOR_FUZZING 0
#define ARTIFICIAL_BUGS 0
./build.sh run
./build.sh test [sha1]