This project implements a TCP-based chat server in C, allowing communication between two clients through a server. The server uses multi-threading to manage connections and relay messages between clients in real-time.
- TCP communication between two clients via a server.
- Multi-threaded server for handling multiple clients simultaneously.
- Real-time message relay between connected clients.
- A C compiler (e.g., GCC).
- Linux environment (or any system supporting socket programming).
-
Clone the repository:
git clone <repository_url> cd <repository_directory>
-
Compile the server and client programs:
gcc -pthread -o server server.c gcc -o client client.c
Run the server program and specify the port number:
./server <port>Example:
./server 8080Run the client program on two separate terminals and specify the server IP address and port number:
./client <server_ip> <port>Example:
./client 127.0.0.1 8080Once both clients are connected to the server:
- Type a message in one client terminal and press Enter.
- The server will relay the message to the other client terminal in real-time.
daytimetcpserver.c: The server program.client.c: The client program.README.md: Documentation for the project.
-
Server:
- Listens for incoming client connections.
- Manages each client connection using a separate thread.
- Relays messages between connected clients.
-
Client:
- Connects to the server.
- Allows users to send messages to the server.
- Receives messages from the server sent by another client.
Server Output:
Server is waiting for connections at port 8080
Connection from 127.0.0.1, port 34567
Connection from 127.0.0.1, port 34568
Two clients connected. Communication enabled.
Client 1 Terminal:
Connected to the server. Type your messages below:
Hello from Client 1!
Message from other client: Hello from Client 2!
Client 2 Terminal:
Connected to the server. Type your messages below:
Hello from Client 2!
Message from other client: Hello from Client 1!
Contributions are welcome! Feel free to submit issues or pull requests to improve the project.
- Inspired by basic TCP socket programming examples.