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.

toml webrocket = "0.1.0"

usage

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

To start an echo server it only needs the following code:

```rust

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;

```

tests

The server implementation was tested with the Autobahn|Testsuite as follows:

```bash $ RUSTLOG=debug cargo run --bin wsserverautobahn

$ 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

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)

check compile options in flags.h (!)

```c

define COMPILEFORFUZZING 0

define ARTIFICIAL_BUGS 0

```

build & run

./build.sh run

build & test

./build.sh test [sha1]