GitHub - Bergenstein/chat_application · GitHub
Skip to content

Bergenstein/chat_application

Repository files navigation

Chat Application

A distributed chat server built with Erlang that enables real-time message communication and broadcasting between multiple users over TCP/IP.

What is Being Built

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

Core Modules

  • 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

How to Install Dependencies

This project requires Erlang/OTP to be installed on your system.

macOS (using Homebrew)

brew install erlang

Linux (Ubuntu/Debian)

sudo apt-get update
sudo apt-get install erlang

Windows

Download the installer from erlang.org

Verify Installation

erl -version

How to Test

Part 1: Chat Server Tests (Single Node)

Start 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().

Part 2: Network Tests (Multiple Nodes/Terminals)

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
> quit

Terminal 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
> quit

Terminal 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
> quit

Available Commands in Client

  • register <username> - Register with the chat server
  • send <username> <message> - Send a private message to another user
  • broadcast <message> - Broadcast a message to all users
  • users - List all registered users
  • unregister - Unregister from the server
  • quit - Exit the client

Software

  • Language: Erlang
  • Framework: OTP (Open Telecom Platform)
  • Architecture: Distributed, fault-tolerant system using gen_server and supervisors
  • Communication: TCP/IP sockets

License

This project is licensed under the MIT License - see the LICENSE file for details.

Getting Started

  1. Ensure Erlang/OTP is installed
  2. Navigate to the project directory
  3. Start an Erlang shell: erl
  4. Follow the testing instructions above

For detailed test cases, see terminal_tests.md


Built with Erlang and OTP for reliable, distributed communication.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages