This is a simple chat application implemented using C socket programming for the Data Communication and Networking assignment.
- Multi-threaded server that handles multiple clients
- Group chat functionality
- Private messaging using the format
@username message - Simple authentication system (username and password)
- Chat logging to a file
You can use the provided Makefile to compile both the server and client:
make allTo compile them individually:
make server
make client./serverThe server will start listening for connections on port 8888.
./clientThis will connect to a server running on localhost (127.0.0.1).
To connect to a server on a different IP address:
./client 192.168.1.100- When you run a client, you will be prompted to enter a username and password.
- After successful authentication, you can send messages:
- Regular messages will be broadcast to all connected clients
- To send a private message, use the format:
@username your message here
- All chat messages are logged in the file
chat_log.txt
Server started on port 8888...
New connection from 127.0.0.1:52890
New connection from 127.0.0.1:52891
Connected to server.
Enter username: alice
Enter password: ******
Welcome to the chat, alice! Type '@username message' for private messages.
SERVER: bob has joined the chat
bob: Hello everyone!
[PM from bob]: How are you doing?
Connected to server.
Enter username: bob
Enter password: ******
Welcome to the chat, bob! Type '@username message' for private messages.
SERVER: alice has joined the chat
[PM to alice]: How are you doing?
The application includes error handling for:
- Socket creation failures
- Connection issues
- Authentication problems
- Thread creation failures
- Message sending/receiving errors
server.c: Implementation of the multi-threaded serverclient.c: Implementation of the clientMakefile: For easy compilationchat_log.txt: Log file created by the server
- For simplicity, the authentication system accepts any password (in a real application, you would implement secure authentication)
- The server is configured to listen on port 8888 by default