srve
srve
allows you to create simple network communication in a server client
model, the server holds a bunch of client connections, each with its own state,
and you can communicate with them via messages.
The server uses a background thread to listen for new connections.
Client
To create a client, we specify the message we will be using.
/* on main */
let c = connect?;
then we can send and receive messages
c.send?;
match c.recv?
we finish by closing the client
c.close?;
Server
To create a server, we simply specify which messages we want to use, and which state to represent connections.
/* on main */
let s = bind?;
you can then setup callback functions for different purposes, such as handling new connections, or new messages, after that we can start the server.
s
.on_connection
.on_message
.run;
Examples
You can try the example code by running cargo run --example server
and then
cargo run --example client
in a different (or multiple) terminal(s), then
write commands to interact with the server.
There is also the broken.rs
example, which I use to test how the server
interacts with 'broken' clients, such as closing unexpectedly, or sending bad
messages, etc.