This project is a simple chat server implemented in C. The server supports sending and receiving messages, adding reactions to messages, and editing messages. It uses a Makefile for compilation.
- Send Chat: Users can send messages to the server.
- Receive Messages: Users can retrieve all messages from the server.
- Add Reactions: Users can add reactions to specific messages.
- Edit Messages: Users can edit their messages.
- Reset Server: Administrators can reset the server data.
- A C compiler (e.g., GCC)
- Make
- Clone the repository:
git clone https://github.com/your-username/chat-server.git cd chat-server
- Compile the server using Make:
make
Start the server by specifying the port number:
./chat-server <port>
For example, to start the server on port 8080:
./chat-server 8080
Send a Message Endpoint: /post Method: POST
user: The username of the sender. message: The message content. Retrieve Messages Endpoint: /chats Method: GET
Add a Reaction Endpoint: /react Method: POST Parameters: user: The username of the reactor. message: The reaction content. id: The ID of the message to react to.
Edit a Message Endpoint: /edit Method: POST
Parameters: id: The ID of the message to edit. message: The new message content. Reset Server Data Endpoint: /reset Method: GET
Code Structure Data Structures
Reaction: Represents a reaction to a message.
struct Reaction {
char user[USERNAME_SIZE];
char message[REACTION_SIZE];
};
Chat: Represents a chat message with reactions.
struct Chat {
uint32_t id;
char user[USERNAME_SIZE];
char message[MESSAGE_SIZE];
char timestamp[TIMESTAMP_SIZE];
uint32_t num_reactions;
Reaction reactions[MAX_REACTIONS];
};
handle_404: Handles 404 Not Found responses.
url_decode: Decodes URL-encoded strings.
add_chat: Adds a new chat message.
add_reaction: Adds a reaction to a chat message.
reset: Resets the server data.
respond_with_chats: Sends all chat messages to the client.
edit_chat: Edits an existing chat message.
handle_edit: Handles edit requests.
handle_post: Handles new message posts.
handle_reaction: Handles reaction additions.
handle_response: Main request handler.
main: Entry point of the server.
Contributions are welcome! Please open an issue or submit a pull request.
For any questions or support, please contact [email protected]