This project involves developing a chat server implemented in the C programming language. The server is designed to handle multiple client connections simultaneously, utilizing threads to ensure smooth and efficient communication.
- glib: A utility library for C programming that provides data structures, macros, and other utilities.
- cJSON: A lightweight JSON parser in C.
sudo apt-get install meson ninja-build
meson setup builddir
meson compile -C builddir
./builddir/servidorR <port>
./builddir/clienteR <ip> <port>
The chat system supports a variety of commands for interacting with the server. Below are the commands you can use and how they are parsed by the system.
-
\identify|<username>Registers a new username.
- Example:
\identify|Juan - Description: The argument is the username you wish to register. The username is unique.
- Example:
-
\whisper|<username>|<message>Sends a private message to a specific user.
- Example:
\whisper|Alice|Hello, how are you? - Description: The first argument after
\whisperis the username of the recipient, and the rest of the message is the content of the private message.
- Example:
-
\broadcast|<message>Sends a message to all connected users.
- Example:
\broadcast|Attention: Scheduled maintenance tonight. - Description: The message will be visible to all users in the chat.
- Example:
-
\getUsersRequests a list of all connected users.
- Example:
\getUsers - Description: This command does not require any arguments and returns a list of currently online users.
- Example:
-
\setStatus|<status>Changes your user status. The status can be one of the following:
- AWAY
- BUSY
- ONLINE
- Example:
\setStatus|ONLINE - Description: The
<status>argument should be one of the predefined statuses. If an invalid status is provided, the system will not update your status.
-
\newRoom|<room name>Creates a new chat room.
- Example:
\newRoom|GameRoom - Description: The room name is specified in the argument following the command.
- Example:
-
\invite|<room name>|<user1>|<user2>|...Invites one or more users to a specific room.
- Example:
\invite|GameRoom|Bob|Carol - Description: The first argument is the room name, and the subsequent arguments are the usernames to invite.
- Example:
-
\acceptInvitation|<room name>Accepts an invitation to join a chat room.
- Example:
\acceptInvitation|GameRoom - Description: The argument is the name of the room you want to join.
- Example:
-
\messageRoom|<room name>|<message>Sends a message to all members of a room.
- Example:
\messageRoom|GameRoom|Welcome everyone! - Description: The first argument is the room name, and the rest is the message that will be sent to all members of that room.
- Example:
-
\getRoomUsers|<room name>
Requests a list of users in a specific room.
- Example:
\getRoomUsers|GameRoom - Description: The argument is the name of the room for which you want to request the user list.
-
\leaveRoom|<room name>Leaves a chat room.
- Example:
\leaveRoom|GameRoom - Description: The argument is the name of the room you wish to leave.
- Example:
-
\byeDisconnects the user from the chat.
- Example:
\bye - Description: This command does not require any arguments and disconnects the user from the server.
- Example:
- Handling Spaces: If the room name or message contains spaces, ensure that the arguments are properly delimited. Use the pipe character
|to separate arguments. - Command Validation: If a command is not recognized or the arguments are invalid, the system will return an error message.