Grubbnet
Grubbnet is a lightweight TCP client/server library, meant for writing networked applications and games. It is basically an evolution and combination of all the TCP boilerplate I usually have to write whenever I work on a networked project.
Grubbnet abstracts socket code, keeps track of connections, and delivers everything back to the developer in a nice list of events. Instead of dealing with raw bytes, Grubbnet operates based on packets that the developer can define. Handling these packets is as simple as grabbing an iterator over the incoming packet queue.
I'm using this crate to develop an online RPG, Antorum. If you want to use it, or are already using it for a project, get in touch!
Usage
Add this to your Cargo.toml
:
[]
= "0.1"
Hosting a barebones server:
let mut server = host?;
loop
Examples
I have written one example so far, which is a simple ping server and client.
cargo run --example simple_server
cargo run --example simple_client
The server will run, waiting for clients to connect and send PingPacket
s, responding with PongPacket
s.
The client will connect and send PingPacket
s on an interval. When 5 pings are sent, the server will kick the client.
Both the simple_server
and simple_client
define the PingPacket
and PongPacket
. When using the crate for
real, if possible you should store packet definitions in a common crate. Also, it goes without saying that
these two packets didn't need to be separate types. However, I wanted to demonstrate the pattern of having
client-only and server-only packets.
Optional Crate Feature - Crypto
There is one optional feature in this crate, crypto
.
Enabling it will give you access to the grubbnet::crypto
module, which is a tiny wrapper around some openssl
and bcrypt
stuff for decrypting bytes with a private key, and hashing/verifying strings. This is useful for writing packets with sensitive data.
I need to write more about how this is used, but for now just know that if you enable this you are required to have the openssl
development
libraries installed on your machine.
// Decrypt some bytes
let = decrypt
.expect;
// Convert those bytes into a UTF-8 plaintext password
let plaintext_password = str from_utf8
.expect;
// Verify plaintext password against some hashed password
if verify?
License
Grubbnet is distributed under the terms of the MIT license. See LICENSE for more details.