Async Hacking 🪓


Back to index

Putting all this into practice

Chat Client

(encryption optional)


Async Server
Accept connections (TCP, UDP, unix sockets, … up to you), handle a message type, and replicate messages to relevant clients.
Async Client
Connect to the server, join a "room", send and receive messages for this room.

Chat Message Type


pub enum Message {
    TextPayload { room: String, nick: String, content: String, }
    JoinRoom { room: String, nick: String }
    CreateRoom { room: String }
}

What structure?

Pick a runtime/ framework/ design philosophy!

asyncstd/ tokio
"batteries included", provide synchronisation, network access, etc
smol + util crates
Compose a larger runtime system from smaller crates. All the tools are there, but need to be assembled in some way.
actix/ ockam
"batteries included" (ish), but will require some work to map async I/O to actors

Boilerplate crate


https://github.com/spacekookie/learning-rust/tree/main/courses/01-advanced-async/exercises/06-async-chat

(great short url)

Other utilities


serde
Serialise data (and pick a format)
futures-rs
Lots of great combinators for working with futures (re-exported from smol)

Have questions? Getting stuck?


YELL AT ME (or the other teaching assistants)!

Good luck 🚀

Back to index