A distributed chat application backend written in Rust that supports peer-to-peer communication over multiple network protocols (UDP, TCP, and Bundle Protocol).
socket-engine: Custom networking engine for handling UDP and TCP connections
- Multi-protocol Support: TCP, UDP, and Bundle Protocol (BP) communication
- Peer-to-Peer Architecture: Direct communication between chat clients
- Message Acknowledgment: Built-in message delivery confirmation system
- Real-time Terminal Interface: Live chat display with network and application events
- Protocol Buffers: Efficient message serialization using protobuf
- Message Status Tracking: Track message states (sending, sent, acknowledged, failed)
- UUID-based Identification: Unique identification for peers and messages
The application consists of several key components:
- ChatModel: Core chat logic and peer management
- TerminalScreen: Interactive terminal-based user interface
- Message System: Handles chat messages with status tracking
- Event System: Network and application event management
- Protocol Buffer Messages: Structured message format for network communication
The application requires two arguments:
- Local endpoint: The address this instance will listen on
- Remote endpoint: The address of the peer to connect to
To test the chat functionality using UDP/BP/TCP protocol:
# Terminal 1 (First peer)
cargo run -- "<PROTOCOL> 127.0.0.1:7777" "<PROTOCOL> 127.0.0.1:6666"
# Terminal 2 (Second peer)
cargo run -- "<PROTOCOL> 127.0.0.1:6666" "<PROTOCOL> 127.0.0.1:7777"- UDP:
udp <ip>:<port> - TCP:
tcp <ip>:<port> - Bundle Protocol:
bp <address>
Messages use Protocol Buffers with the following structure:
message ProtoMessage {
string uuid = 1;
string sender_uuid = 2;
int64 timestamp = 3;
string room_uuid = 4;
oneof msg_type {
TextMessage text = 5;
AckMessage ack = 6;
}
}- TextMessage: Regular chat messages containing text content
- AckMessage: Acknowledgment messages confirming receipt
The application provides a real-time terminal interface displaying:
- Chat Messages: Recent messages with timestamps and status indicators
- Network Events: Connection status, data transmission events
- Application Events: Internal application state changes
- Message Status: Visual indicators for message delivery states
SENDING: Message is being transmittedSENT: Message has been sent successfullyACKED: Message has been acknowledged by recipientFAILED: Message transmission failedRECEIVED: Message received from peer