This project is a multi-client TCP-based group chat application built in C. It includes both a server and client implementation, enabling real-time communication between multiple users over a network. The server employs efficient I/O multiplexing using the select system call, while the client offers a simple interface for connecting to the server and participating in the chat. Shared utility functions are included for streamlined socket management.
- Concurrent Client Connections: Manages multiple clients simultaneously using a single-threaded approach with select.
- Real-Time Messaging: Broadcasts messages from any client to all other connected clients efficiently.
- Dynamic Client Management:
- Handles new connections dynamically.
- Removes inactive or disconnected clients gracefully.
- Server-Side Commands:
- quit: Shuts down the server and disconnects all clients.
- Comprehensive Error Handling: Ensures stability and clean shutdown during unexpected errors.
- User Authentication: Allows users to set a username when connecting to the server.
- Real-Time Chat: Sends messages to the server for broadcasting to other connected clients.
- Interactive Interface:
- Displays incoming messages in real-time.
- Supports text input for sending messages.
- Disconnection Handling: Handles clean disconnection from the server when a client exits or the server shuts down.
- Socket Utilities: Common functions for socket creation, error handling, and IPv4 address initialization, shared between the server and client.
- Server
- Initializes a TCP socket, binds it to a specified port, and begins listening for incoming client connections.
- Manages incoming and outgoing messages and broadcasts them to all connected clients.
- Client
- Connects to the server using the server’s IP and port.
- Sends a username upon connection, which is announced to other clients.
- Allows users to send messages and receive real-time updates from other users in the chat.
- Operating System: Linux (or any POSIX-compliant system).
- Dependencies:
- gcc (for compilation).
- Basic networking libraries (sys/socket.h, arpa/inet.h, etc.).
-
Clone this repository
git clone https://github.com/AdrianMosnegutu/Multiplexed-Chat-Server.git cd Multiplexed-Chat-Server
-
Compile the server and client
gcc -o chat_server server.c utils/server_utils.c utils/general_utils.c
gcc -o chat_client client.c utils/client_utils.c utils/general_utils.c
-
Run the server
Start the server to listen for incoming connections:
./chat_server
-
Run any number of clients
Clients can connect to the server using the compiled client binary:
./chat_client
utils/
general_utils.h
/server_utils.h
/client_utils.h
: Header files for respective utility functions.general_utils.c
: Shared utilities for socket creation, IPv4 address initialization, and error handling.server_utils.c
: Utility functions for server-side socket management and error handling.client_utils.c
: Utility functions for client-side socket management and input handling.
server.c
: Main server logic, including connection handling and message broadcasting.client.c
: Main client logic, including server connection, message sending, and receiving.
This project is licensed under the MIT License. See the LICENSE file for details.