This Erlang module implements a simple chat server that listens for connections on a certain port and handles incoming client connections.
To build the project, you need to have Erlang and rebar3 installed on your system.
-
Clone the repository to your local machine:
git clone https://github.com/alihaidersays/chat_server.git
-
Navigate to the project directory:
cd chat_server
-
Compile the project using rebar3:
rebar3 compile
To run the chat server, follow these steps:
-
Ensure that the project is compiled (see "Building the Project" section).
-
Start the Erlang shell:
rebar3 shell
-
In the Erlang shell, start the chat server by executing the following command:
chat_server:start().
This will start the server listening on port 1234.
- In another command terminal (client 1), execute the following command to connect to the chat server using Telnet:
telnet localhost 1234
This command will attempt to establish a TCP/IP connection to the chat server running on localhost (your own computer) on port 1234. If successful, you'll be connected to the chat server and can interact with it.
Repeat this step for multiple clients.
To use the individual functionalities of the chat server, follow these steps:
-
Create a Room: To create a chat room, send a command in the format "CREATE RoomName" to the server. For example:
CREATE Room1
-
Destroy a Room: To destroy a chat room, send a command in the format "DESTROY RoomName" to the server. For example:
DESTROY Room1
-
List Available Rooms: To list all available chat rooms, send the command "LIST" to the server. For example:
LIST
-
Join a Room: To join a chat room, send a command in the format "JOIN RoomName" to the server. For example:
JOIN Room1
-
Leave a Room: To leave a chat room, send a command in the format "LEAVE RoomName" to the server. For example:
LEAVE Room1
-
Send a Message: To send a message to a chat room, send a command in the format "SEND RoomName Message" to the server. For example:
SEND Room1 Hello
-
List Members: To list all members of a specified chat room, send a command in the format "LISTMEMBERS RoomName" to the server. For example:
LISTMEMBERS Room1
-
Send Private Message: After knowing the names of members using the previous command, you can send a private message to a member in the same chat room by sending the command "SENDPRIVATE RoomName UserName Message" to the server. For example:
SENDPRIVATE Room1 User1 Hello
Remember to replace "RoomName", "UserName" and "Message" with the appropriate values for your chat room, user and message. Additionally, ensure that the server is running and properly configured to handle client connections.
- This is a basic example and may not be suitable for production use.
- Error handling and robustness features are not included for simplicity.