A client implementation with for a server handling Queue-Based Reader-Writer Locking mechanism I created as a semester project in my 5th semster under supervision of Dr. Khawaja Umar Suleman along with my fellows Muhammad Rehman and Abdullah Masood.
Client implementation of the Server (handling Queue-Based Reader-Writer Locking mechanism), allowing the client to download files, look after his files uploaded to the server, and check for his file and data uplaoded to the server and maintaining the allocated storage space to him, covering basic user authentication allowing him to check for storage space covering a particular user authentication in C. The user can create his account using name and password in the server. After that the user can type in various commands and perform Upload, Download And View queries after logging in to his account.
-
This project has a C program source code for a client implementation in C such that a client looks after his files uploaded to server and check for the storage he has used ,covering basic implementation of authentication in C.
-
For this C code use make file to build it and then the C program will be compiled into main.exe.
- Find the Server Repository of this Project Here FilesSphere-Server.
client.c
: The source code for the client-side application.Makefile
: Used to build, clean, and run the project.helper_utilities.c
: Contains Queries funciton's utility modules.helper_queries.c
: Contains Queries code/ funcitons the user executes.helper.h
: Initialization of globally accessible functions.Makefile
: Used to build, clean, and run the project.
- Socket Initialization: Creates a TCP server that listens on a specified port (
PORT
). - Client Connections: Handles up to a maximum number of clients (
MAX_CONNECTIONS
) concurrently. - Threaded Client Handling: Spawns a new thread for each client connection to handle client-specific tasks independently.
- User Information Storage: Stores and manages user-specific data (e.g., username, read/write counts, and request queues).
- User Initialization: Creates a new
UserInfo
entry for a client if the user is not already connected. - Global User List: Maintains a list of active users, limited by
MAX_CONNECTIONS
.
- Request Queue: Manages a queue of requests (
READ
orWRITE
) for each user. - Read Operations: Allows multiple clients to read simultaneously, provided no write is in progress.
- Write Operations: Allows only one client to write at a time, blocking reads and other writes until the write completes.
- Queue Processing: Processes requests in a first-come, first-served order for fairness.
- Task Options: Supports a range of operations based on client requests:
- Upload/Delete/Update (Write operations): Requires exclusive access to user data.
- Download/View (Read operations): Allows shared access unless a write is ongoing.
- Read-Write Execution: Manages read and write operations with functions
startRead
,finishRead
,startWrite
, andfinishWrite
to ensure safe concurrent access.
- Registration Logic: Registration of the user using his name and password(e.g., storing of credentials like name and passwords).
- Authentication Logic: Authentication of user using his name and password with which he registered his account(e.g., name and password checks).
- Username Retrieval: Retrieves the username for each client upon connection.
- Mutex Locks and Condition Variables: Uses mutexes and condition variables to ensure safe access to shared data.
- Global Connection Control: Limits the maximum number of client connections using a global mutex and condition variable.
- Upload: Upload files to the server. Files are saved in the User's directory on the server, the server alos asks user to replace if the file exists otherwise will create a copy automatically.
- Download Download files from the server. The requested file is sent from the server to the client.
- View View file details, such as file name, size, and creation date, if available.
- Delete Delete files from the server. The specified file is removed from the server’s storage.
- Update Update or replace existing files on the server with a new version.
The following commands are used to compile, clean, and run the executable of this C program:
make
: Compiles and builds the program, generating theclient.exe
executable.make clean
: Removes the existing executable and any intermediate compiled files.make run
: Compiles the program (if necessary) and runs the executable. If the source files are unchanged and the executable exists, it directly runs the program.make clean run
: Cleans any previous builds, compiles the program, and then runs the executable.
gcc
: A popular C compiler, part of the GNU Compiler Collection.make
: A build tool for automating the process of compiling and managing dependencies.libc6-dev
: Development libraries and headers for the GNU C Library, essential for compiling C programs.
Before building the program, ensure that the necessary build tools (compiler, make, libc6-dev) are installed on your system. On a Debian-based system (e.g., Ubuntu), you can install them using the following commands:
sudo apt-get update
sudo apt-get install build-essential
Once the tools are installed, navigate to the directory containing the Makefile
and run the desired command (e.g., make
or make run
).