WebRocket 🚀 is a WebSocket server library programmed in Rust from scratch.
 
 
Go to file
Tobi d8dd572ef8
update text
2023-02-19 16:40:51 +01:00
src add nice api 2023-02-05 21:56:15 +01:00
tests update cargo 2023-01-26 20:23:46 +01:00
.gitignore add autobahn reports to .gitignore 2023-01-26 20:08:32 +01:00
Cargo.toml add new api to connection 2023-02-03 00:06:54 +01:00
LICENCE Create LICENCE 2023-01-26 20:25:53 +01:00
README.md update text 2023-02-19 16:40:51 +01:00

README.md

webrocket

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.

installation

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"

usage

Since I am a big closure fan, many functions are offered as clousures, like on_connection or on_message.

To start a simple server it only needs the following code:


let mut ws = WebSocket::bind("0.0.0.0:3000").await?;

ws.on_connection(|wsc| {
    // send a message to the client
    wsc.emit("hello".into(), "world".into());

    // receive a message from the client
    wsc.on("howdy".to_string(), |_, msg| {
        info!("{}", msg); // prints "stranger"
    });

});

ws.listen().await;

The client can be started using webrocket-client.

const socket = new WebRocket("ws://127.0.0.1:3000");

// receive a message from the server
socket.on("hello", (msg) => {
  console.log("hello", msg); // prints "world"
});

// send a message to the server
socket.emit("howdy", "stranger");

tests

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.

standards

already implemented

still to make

Side project

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.

requirements (cpp)

  • CMake 3.22.1 brew install cmake
  • A C++17 compatibler compiler

check compile options in flags.h (!)

#define COMPILE_FOR_FUZZING 0
#define ARTIFICIAL_BUGS     0

build & run

./build.sh run

build & test

./build.sh test [sha1]