A distributed chat server built with Erlang that enables real-time message communication and broadcasting between multiple users over TCP/IP.
This project implements a distributed chat system with the following features:
- User Registration & Management: Register/unregister users with unique identifiers
- Private Messaging: Send direct messages between users
- Broadcasting: Send messages to all connected users
- User Listing: View all currently registered users
- TCP Networking: Network communication between client and server using TCP sockets
- Supervision Trees: Fault-tolerant architecture using OTP supervisors
- Erlang Processes: Leverages Erlang's lightweight processes for scalability
- chat.erl - Main chat server using
gen_server - client_tcp.erl - TCP client for connecting to the chat server
- listener_tcp.erl - TCP listener/server socket handler
- chat_sup.erl - Supervisor for the chat server
- client_sup.erl - Supervisor for TCP clients
- client_connection.erl - Handles individual client connections
- chat_bot.erl - Bot functionality for automated chat interactions
This project requires Erlang/OTP to be installed on your system.
brew install erlangsudo apt-get update
sudo apt-get install erlangDownload the installer from erlang.org
erl -versionStart the Erlang shell and run the following commands:
% Compile the chat module
c(chat).
% Start the chat server
chat:start_link(chat).
% Register users
chat:register(chat, juan, self()).
chat:register(chat, elizaveta, self()).
% List registered users
chat:list_users(chat).
% Send private messages
chat:send(chat, juan, elizaveta, "Hi Elizaveta!").
flush().
% Broadcast to all users
chat:broadcast(juan, "Hey everyone!").
flush().
% Unregister a user
chat:unregister(chat, juan).
% Stop the server
chat:stop().Terminal 1 - Server:
c(chat).
c(listener_tcp).
c(client_tcp).
chat:start_link(chat).
listener_tcp:start_link(5091).Terminal 2 - Client (Juan):
c(client_tcp).
client_tcp:start({127,0,0,1}, 5091).
% In the client prompt:
> register juan
> send elizaveta Hey, pub after work?
> users
> broadcast See you at 6 pm!
> unregister
> quitTerminal 3 - Client (Elizaveta):
c(client_tcp).
client_tcp:start({127,0,0,1}, 5091).
% In the client prompt:
> register elizaveta
> send juan Sounds good!
> users
> unregister
> quitTerminal 4 - Client (Rosaria):
c(client_tcp).
client_tcp:start({127,0,0,1}, 5091).
% In the client prompt:
> register rosaria
> broadcast What are you talking about?
> send juan Count me in!
> users
> unregister
> quitregister <username>- Register with the chat serversend <username> <message>- Send a private message to another userbroadcast <message>- Broadcast a message to all usersusers- List all registered usersunregister- Unregister from the serverquit- Exit the client
- Language: Erlang
- Framework: OTP (Open Telecom Platform)
- Architecture: Distributed, fault-tolerant system using
gen_serverand supervisors - Communication: TCP/IP sockets
This project is licensed under the MIT License - see the LICENSE file for details.
- Ensure Erlang/OTP is installed
- Navigate to the project directory
- Start an Erlang shell:
erl - Follow the testing instructions above
For detailed test cases, see terminal_tests.md
Built with Erlang and OTP for reliable, distributed communication.
