Code Monkey home page Code Monkey logo

kahleryasla / multi-user-messaging Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 14.88 MB

Multi-threaded console chat application implemented in C, consisting of both server and client components. The server manages user contacts and messages, while the client provides a user-friendly interface to interact with the server. The communication between the server and client is facilitated through socket programming.

C 100.00%
c chat-application console-application multithreading networking socket-programming readme

multi-user-messaging's Introduction

Multi_User_Messaging

Multithreaded Realtime Console Chat App ๐Ÿ’ฌ

Featured Photo

List of Contents:


Project Description:

Multi-threaded console chat application implemented in C, consisting of both server and client components. The server manages user contacts and messages, while the client provides a user-friendly interface to interact with the server. The communication between the server and client is facilitated through socket programming.

Built With:

Programming Languages:

  • C

Frameworks and Technologies:

  • No frameworks used (only standard libraries)
  • Only C standard libraries for Unix-like systems
  • Csv file system for storing messages and contacts

Libraries and Dependencies:

  • Standart Libraries --> Listed Only Important Ones:
    • arpa/inet.h (for socket programming)
    • unistd.h (for read and write functions)
    • pthread.h (for multithreading)
    • time.h (for date and time functions)
    • sys/types.h (for socket programming)
    • sys/stat.h (for file permissions)
  • External libraries:
  • Dependencies:
    • gcc (GNU Compiler Collection)

Compatible with:

+ Linux

+ MacOS

- Windows (needs to include winsock.h instead of arpa/inet.h)

Usage:

It is well described with screenshots in Screenshots section.


Project Structure:

.
โ”œโ”€โ”€ Contacts
โ”‚   โ”œโ”€โ”€ userID.csv // example
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ Messages
โ”‚   โ”œโ”€โ”€ userID.csv // example
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ Public // this folder is not included in the project
โ”‚   โ””โ”€โ”€ Project ScreenShots
โ”‚       โ””โ”€โ”€ ...
โ”œโ”€โ”€ Readme.md
โ”œโ”€โ”€ ansiTerminalColors.h // for colored output
โ”œโ”€โ”€ client // executable of client component
โ”œโ”€โ”€ client.c // source code of client component
โ”œโ”€โ”€ server  // executable of server component
โ””โ”€โ”€ server.c // source code of server component

5 directories, 24 files

Future Improvements:

+ Add a proper database instead of CSV files (maybe SQLite or PostgreSQL)

+ Add a decent GUI (maybe with Qt)

+ Listing from a specified user (in messages)

To be Fixed:

- Bug: server crash when a client disconnects

- Bug: deleting a message from a user deletes all messages from that user

- Bug: returning to the main menu after deleting a message from a user returns to the same menu

Screenshots:

Screenshot 1

Screenshot 2

Screenshot 3

Screenshot 4

Screenshot 5

Screenshot 6

Screenshot 7

Screenshot 8

Screenshot 9

Screenshot 10

Screenshot 11

Screenshot 12

Screenshot 13

Screenshot 14

Code Documentation

server.c

Function Prototypes and Explanations:

  1. Handler function for each client thread

    void *handleClient(void *arg)

    This function runs in a separate thread for each connected client. It handles incoming messages from the client, interprets user input, and performs corresponding actions.

    Input void *arg (client socket)
    Output None

  1. Getter function for the current date and time

    Date getCurrentDateAndTime()

    This function retrieves the current date and time and returns it as a Date structure.

    Input None
    Output Date (structure)

  1. Response function for listing contacts

    void listContacts(char *userID, int client_socket)

    This function reads the user's contacts from a CSV file and sends them to the client.

    Input char *userID, int client_socket
    Output Sends a list of contacts to the client

  1. Response function for listing messages from a user

    void listMessagesFromUser(char *userID, Message message, int client_socket)

    This function reads messages from a CSV file, filters them based on the specified user, and sends the result to the client.

    Input char *userID, Message message, int client_socket
    Output Sends messages from a specified user to the client

  1. Response function for deleting a message

    void deleteMessage(char *userID, Message message, int client_socket)

    This function deletes a specified message from the user's message history and sends a confirmation or error message to the client.

    Input char *userID, Message message, int client_socket
    Output Sends a confirmation or error message to the client

  1. Response function for adding a user

    void addUser(char *userID, Message message, int client_socket)

    This function adds a user to the contact list and sends a confirmation message to the client.

    Input char *userID, Message message, int client_socket
    Output Sends a confirmation message to the client

  1. Response function for deleting a user

    void deleteUser(char *userID, Message message, int client_socket)

    This function deletes a specified user from the contact list and sends a confirmation or error message to the client.

    Input char *userID, Message message, int client_socket
    Output Sends a confirmation or error message to the client

  1. Response function for sending a message

    void sendMessage(char *userID, Message message, int client_socket)

    This function sends a message from the user to another user, updating the recipient's message history.

    Input char *userID, Message message, int client_socket
    Output Sends a confirmation message to the client

  1. Response function for checking messages

    void checkMessages(char *userID, int client_socket)

    This function reads the user's messages from a CSV file and sends them to the client.

    Input char *userID, int client_socket
    Output Sends a list of messages to the client

  1. Function for sorting messages in a CSV file

    void sortTheCSVFileAccordingToDate(char *messagesCSVPath)

    This function sorts the messages in a CSV file based on their dates.

    Input char *messagesCSVPath
    Output None

  1. Function for comparing two dates

    int compareDates(const Date *date1, const Date *date2)

    This function compares two date structures and returns the result.

    Input const Date *date1, const Date *date2
    Output Returns an integer (comparison result)

  1. Function for creating CSV files if they don't exist

    void createCSVIfNotExists(char *userID)

    This function creates contacts and messages CSV files if they don't exist for the given user.

    Input char *userID
    Output None

client.c

Function Prototypes and Explanations:

  1. Function for displaying the menu

    void displayMenu()

    This function displays the menu options for the user.

    Input None
    Output None

  1. Request function for sending a message to the server

    void sendMessageToServer(int client_socket, char *userID)

    This function takes user input for sending a message, constructs a Message structure, and sends it to the server.

    Input int client_socket, char *userID
    Output Sends a message to the server

  1. Request function for receiving messages from the server

    void receiveMessagesFromServer(int client_socket, char *userID)

    This function receives and displays messages from the server.

    Input int client_socket, char *userID
    Output Displays messages received from the server

  1. Request function for adding a user to the contacts list

    void addUserToContacts(int client_socket, char *userID)

    This function takes user input for adding a contact, constructs a Message structure, and sends it to the server.

    Input int client_socket, char *userID
    Output Adds a user to the contacts list

  1. Request function for deleting a user from the contacts list

    void deleteUserFromContacts(int client_socket, char *userID)

    This function takes user input for deleting a contact, constructs a Message structure, and sends it to the server.

    Input int client_socket, char *userID
    Output Deletes a user from the contacts list

  1. Request function for displaying the list of contacts

    void displayContacts(int client_socket, char *userID)

    This function requests and displays the list of contacts from the server.

    Input int client_socket, char *userID
    Output Displays the list of contacts

  1. Request function for displaying messages from a specified user

    void displayMessagesFromUser(int client_socket, char *userID)

    This function takes user input for a specified user, constructs a Message structure, sends it to the server, and displays the response.

    Input int client_socket, char *userID
    Output Displays messages from a specified user

  1. Request function for deleting a message from a specified user

    void deleteMessageFromUser(int client_socket, char *userID)

    This function takes user input for a specified user and message, constructs a Message structure, sends it to the server, and displays the response.

    Input int client_socket, char *userID
    Output Deletes a message from a specified user

  1. Function for clearing the console screen

    void clearScreen()

    This function clears the console screen.

    Input None
    Output None

ansiTerminalColors.h

Function Prototypes and Explanations:

  1. Macro function for printing colored text to the console

    // XXX is the color name
    #define LogXXX(x) printf(ANSI_COLOR_XXX x ANSI_COLOR_RESET)

    This function prints colored text to the console.

    Input char *text, char *color
    Output None

multi-user-messaging's People

Contributors

kahleryasla avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.