An Elixir-based real-time messaging platform created with Elixir to facilitate communication between users over TCP connections. This system supports setting nicknames, listing active users, sending direct messages, and broadcasting messages to all users. A Java client is provided to interact with the chat server seamlessly.
- Nickname Management: Users can set and change their unique nicknames.
- User Listing: Retrieve a list of all active nicknames.
- Direct Messaging: Send messages to specific users.
- Broadcast Messaging: Send messages to all registered users.
- Concurrent Connections: Supports multiple simultaneous TCP connections.
- Error Handling: Validates commands and provides appropriate feedback.
- Persistent State: Utilizes ETS tables for state management and crash recovery.
- Multiple Nodes: Proxy Servers can be ran on different nodes
The system consists of two main Elixir modules and a Java client:
-
Chat.Server
- Type: GenServer
- Role: A globally-registered GenServer that manages nicknames and message handling using ETS tables.
-
Chat.ProxyServer
- Type: Proxy Server
- Role: Handles incoming TCP connections, spawns proxy processes for each client, each process interfaces with the
Chat.Server.
-
Java Client
- Functionality: Connects to the
Chat.ProxyServer, allows users to input commands, and displays messages from other users.
- Functionality: Connects to the
Ensure the following software is installed on your system to successfully set up and run the Chat System:
- Elixir: Version
1.17.2 - Erlang/OTP: Version
27.0 - Java: JDK
17 - Mix: Included with Elixir for managing projects
- Elixir: Installation Guide
Note: These are the versions used during development and testing. While newer versions may be compatible, using these specific versions ensures compatibility and reduces the likelihood of encountering unexpected issues.
git clone https://github.com/rubengill/ElixirChatSystem.git
cd ElixirChatSystemmix compileiex -S mixChat.ProxyServer.start()Note: Ensure in the root mix directory
javac ChatClient.javaNote: Ensure in the root mix directory
java ChatClientUsers interact with the chat system using specific commands. Commands are case-sensitive.
- Command Variants:
/NICK,/N - Usage:
/NICK <nickname><nickname>: The nickname to register the process.
Rules:
- Must start with an alphabet.
- Can contain alphanumeric characters and underscores.
- Maximum length of 10 characters.
- Nicknames must be unique.
- Required before sending or receiving messages.
Examples:
/NICK homer/N homer
Responses:
- Success: Confirmation message.
- Failure: Error indicating nickname is invalid or already in use.
- Command Variants:
/LIST,/L - Usage:
/LIST
Description: Retrieves a list of all currently registered nicknames.
Examples:
/LIST/L
Responses:
- Success: Retreives all active users.
- Failure: Error indicating failure to retreive users.
- Command Variants:
/SEND,/S - Usage:
/SEND <nicknames> <message><nicknames>: One or more nicknames separated by semicolons (;).<message>: The message to be sent.
Examples:
/SEND homer hello world/S homer;bart hello everyone
Responses:
- Success: Message delivered confirmation.
- Failure: Error indicating invalid recipients.
- Command Variants:
/BCAST,/B - Usage:
/BCAST <message>
Examples:
/BCAST hello all/B this is a broadcast message
Responses:
- Success: Message broadcast confirmation.
- Failure: Error sending message.
To ensure the chat system functions correctly, follow these testing steps:
-
Start the Chat Server and Proxy Server
- Run the following command:
iex -S mix Chat.ProxyServer.start()
- Run the following command:
-
Run Multiple Java Clients
- Open multiple terminal windows and run the Java client in each:
Note: Ensure ChatClient.java is compiled
java ChatClient -
Set Nicknames
- In each client, set a unique nickname:
/NICK user1 /NICK user2
- In each client, set a unique nickname:
-
List Active Users
- Use the
/LISTcommand to verify active nicknames:/LIST
- Use the
-
Send Direct Messages
- From
user1, send a message touser2:/SEND user2 Hello, user2!
- From
-
Broadcast Messages
- From
user1, broadcast a message to all users:/BCAST Hello!
- From
-
Change Nicknames
- Change a user's nickname and ensure the update reflects across all clients:
/NICK newUser1
- Change a user's nickname and ensure the update reflects across all clients:
-
Invalid Commands
- Test invalid commands to ensure proper error handling:
/RANDOM /SEND hello /NICK
- Test invalid commands to ensure proper error handling:
This project is licensed under the MIT License.