A simple application where users can talk to each other in rooms.
Run make
to start Redis and cargo run
to start the server.
You can then connect to the server using nc
or telnet
eg nc localhost 8000
>help
Commands:
>help - Display commands
>exit - Close connection
>list - List rooms
>me - Your user info
>set-username name - Set username
>create-room room - Create room
>join-room room - Join room
Rooms and messages are persisted using Redis. Every time the server starts, rooms are fetched from Redis and broker tasks are spawned for each one.
Each broker task will have an mpsc Sender
stored in a map, which is cloned everytime someone joins a room. Here are the events it expects:
-
BrokerEvent::JoinRoom
- The broker keeps a map of who is currently connected to the room. When someone joins, a channel is created and they're inserted to the map with theirSender
. Then a task is spawned with theReceiver
and usersTcpStream
, which waits for messages and writes them to the user. -
BrokerEvent::LeaveRoom
- This removes a user from the brokers users map. This causes theSender
to get dropped, which then results in the receiver task closing. -
BrokerEvent::Message
- This sends a message to all users inside the room.