Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Socket Programming Chat Application

This is a simple chat application implemented using C socket programming for the Data Communication and Networking assignment.

Features

  • 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

Compilation Instructions

You can use the provided Makefile to compile both the server and client:

make all

To compile them individually:

make server
make client

Running the Application

Starting the Server

./server

The server will start listening for connections on port 8888.

Starting a Client

./client

This 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

Usage Instructions

  1. When you run a client, you will be prompted to enter a username and password.
  2. 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
  3. All chat messages are logged in the file chat_log.txt

Sample Output

Server Output

Server started on port 8888...
New connection from 127.0.0.1:52890
New connection from 127.0.0.1:52891

Client 1 Output

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?

Client 2 Output

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?

Error Handling

The application includes error handling for:

  • Socket creation failures
  • Connection issues
  • Authentication problems
  • Thread creation failures
  • Message sending/receiving errors

Code Structure

  • server.c: Implementation of the multi-threaded server
  • client.c: Implementation of the client
  • Makefile: For easy compilation
  • chat_log.txt: Log file created by the server

Notes

  • 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

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages