This project is a simple, terminal-based multi-client TCP chat application, developed using the C programming language and the SDL (Simple DirectMedia Layer) library, specifically the SDL_net module. Clients can connect to the server, send and receive messages, and chat in real time.
- Supports up to 10 clients connected simultaneously.
- Allows clients to set a username when connecting to the server.
- Messages sent by clients are broadcast to all connected clients (except the sender).
- Uses TCP protocol for reliable, connection-oriented communication between clients and server.
- Utilizes SDL_net for managing network connections and socket communication.
demo.mp4
To get started with this project, follow the steps below:
-
Install build tools and SDL libraries
-
Debian/Ubuntu:
sudo apt install gcc make libsdl2-dev libsdl2-net-dev -
Fedora/RHEL/CentOS:
sudo dnf install gcc make SDL2-devel SDL2_net-devel -
OpenSUSE:
sudo zypper install gcc make SDL2-devel SDL2_net-devel -
Arch Linux:
sudo pacman -S gcc make sdl2 sdl2_net -
If your Linux distribution is not listed, you can find instructions for installing the SDL libraries from source here.
-
-
Clone the repository
git clone https://github.com/cristianscheid/multi-client-tcp-chat.git cd multi-client-tcp-chat -
Build the project
make
-
Start the server
./build/server- You should see the message: "Server is up and running."
- The server listens on 127.0.0.1:2000 (localhost).
-
Optional - Change the server address on the client (for connections from another machine)
- By default, clients connect to 127.0.0.1 (localhost).
- To connect from another machine, modify the
SERVER_HOSTconstant insrc/client.cwith the server's IP address. - After making the change, run
make cleanandmaketo rebuild the project. - Ensure the firewall on both the server and client allows traffic on port 2000.
-
Start the client(s)
./build/client- You should see the message: "Welcome to the Multi-Client TCP Chat!"
- Open a new terminal for each client you want to connect (up to 10 clients).
-
Interact with the clients
- Set your name and send messages in the chat.
- The server will display all received messages.
- Clients will see messages sent by others.
-
To stop
- Press Ctrl + C to stop the server or exit a client.
Distributed under the MIT License. See LICENSE.txt for more information.