Server_in_C
is a server-client application written purely in C, and designed to handle multiple client connections simultaneously. The server uses sockets for network communication and supports parallel processing of requests using fork()
to spawn a new process for each independent client. This demo-server handles any client-side requests asking for a solution to numerical matrix-inversion and k-means clustering problems.
- Multiple Client Connections: The server can handle multiple clients simultaneously using the
fork()
system call, creating a new process for each client. - Socket Communication: Utilizes TCP sockets for reliable communication between the server and clients.
- Command Handling: The server processes specific commands from clients for matrix inversion and k-means clustering.
- File Transfer: Supports receiving data files from clients and sending result files back to clients.
- Logging: Logs runtime errors and significant events to log files.
- Configurable Port: The server can be started on any specified port, making it flexible for various network environments.
- GCC (GNU Compiler Collection)
- Make
- Linux environment (recommended)
readline
library for client-side command-line interface
To compile and run the server and client, follow these steps:
-
Clone the repository:
$ git clone https://github.com/TheSUPERCD/Server_in_C.git
-
Navigate to the project directory:
$ cd Server_in_C
-
Compile the server and client using
make
:$ make
To start the server, run the following command:
$ ./server -p <port>
Replace <port>
with the port number you want the server to listen on.
Example:
$ ./server -p 8080
To start the client and connect to the server, run the following command:
$ ./client -ip <server_ip> -p <server_port>
Replace <server_ip>
with the server's IP address and <server_port>
with the port number the server is listening on.
Example:
$ ./client -ip 127.0.0.1 -p 8080
Once connected, clients can send commands to the server via a command-line interface. The client supports history and auto-completion for ease of use.
The server processes the following commands:
-
Matrix Inversion (
matinvpar
): This command computes the inverse of a given matrix.Usage:
$ matinvpar -n <matrix_size> -I <init_type> -P <print_switch> -m <max_randnum>
Example:
$ matinvpar -n 4 -I fast -P 1 -m 10
-
K-Means Clustering (
kmeanspar
): This command performs k-means clustering on a dataset.Usage:
$ kmeanspar -f <file_path> -k <num_clusters>
Example:
$ kmeanspar -f ./data/kmeans-data.txt -k 3
The client will then send the data file to the server.
-
Shutdown: This command gracefully shuts down the server process auto-spawned for the client.
Usage:
$ shutdown
- -h: Print the help message.
- -p port: Listen on the specified port number (defaults to port 8080).
- -d: Run as a daemon.
- -s strategy: Specify the request handling strategy (only the
fork
strategy is implemented, the program defaults to this setting).
Example:
$ ./server -p 8080 -s fork
- -h: Print the help message.
- -ip server_ip: Specify the server IP address (defaults to localhost ip).
- -p server_port: Specify the server port number (defaults to port 8080).
Example:
$ ./client -ip 127.0.0.1 -p 8080
- Thanks to Microsoft and GitHub Copilot for providing a great template for this
README.md
file.