Skip to content

An AI-KNN algorithm system for classifying vectors, As part of the final project for Advanced Programming course, Bar-Ilan University.

Notifications You must be signed in to change notification settings

TalMizrahii/AP1-KNN-Multithreaded-TCP-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


C++
Advanced-Programming-1

This github repository is for the final assignment given in Advanced Programming 1 course, Bar Ilan University.

DescriptionImplementationInstalling And ExecutingAuthors

Description

The final project seats in the "main" branch!

This program has two components, a Server and a client. The Server is a TCP server, which can receive two CSV files. One of the files contains vectors of doubles and a specific classification, and the other file contain vectors of doubles with no classification. The Client can connect to the server, enter a path to the files, and ask the server to calculate the classification of each vector from the unclassified file using KNN algorithm. The server can send to the client the result, and if the client wishes to, it can can send it to a file in the client's computer.

adfbh

The client receives two system arguments. The IP address of the server, and his port number. The server gets only a port number to bind to his main socket.

After initiation, the client connects to the server. The server sends the client a menu, and from it, the client can choose a command for the server.

The menu looks like this:

1

The user can choose any option from the menu. If he enters a choice outside of the menu, the server will reply "invalid input" message and will send the menu again.

In the first option, the user will be asked to upload files to the server. He will be asked to enter a path to a classified CSV file, and a path to an unclassified CSV file. The client will automatically send the content of the files to the server. This option will look like that:

3

If the user asks for the algorithm settings, the server will send him the current settings of the KNN algorithm. The message with the default settings looks like that:

2

If he wants no changes to be made, he can press ENTER and the server will send the menu again. If the user wants to change the settings, he can enter a new K element, and a metric of his choice from these options:

image

image

image

image

image

In the third option, the client can just classify the data in the server. If no files were uploaded, the server will reply with an error message, and send the menu again. This part will look like this:

4

In option number 4, the client can request the result of the classification. The server will send the client the result of each vector in the order he received it. If no classification command is performed or no files were uploaded, the server will send an error message. The result will be displayed like that:

5

The last operational option is to download the results to the client's computer. If the user asks for it, the user will be asked to enter a path to store the file. After that, the server will send the results and the client will write them to the file. A message of validation will be presented to the client when the download will complete. If no data or results exist within the server, an error message will be sent. The communication looks like this:

6

And the content of the file will look like that:

7

The last option (8) is to close the connection. all data will be released and the client socket will be closed. The server will move to the next connection.

Implementation

Both server and client share the IO directory. This directory's purpose is to allow them to communicate threw different IO ways, such as sockets, keyboard io, etc. They use the AbstractDefaultIO to polymorphism the IO tool they use. In this program, we use the TCP socket IO. We implemented a self-protocol to transfer data using the SocketIO read and write. The protocol adds the char "$" to the end of the message we want to send. When we read the message in the read method, the protocol concatenates the data (because of the TCP segmentation mechanism), to ensure all data will be received as one message.

client

The Clients implementation is relatively basic. It uses "operations" to fulfill the user requests, such as printing the results of the classification or entering a path to a file. The communication with the server is performed as a "ping pong" talk. If the client sends a message to the server, it can't send a repetitive message until the server replies with a message of its own. All client operations are made sequentially, except the "download results". in this option, the client opens a new thread, which gives him the ability to concurrently make new commends while he downloads the results to his computer.

image

Server

The server's implementation is based on a CLI with the client. After the server accepts a new client, it opens a thread for this client, which gives him the ability to concurrently accept new clients and handle them. The server implements the Command design pattern, giving him the modular option to add and remove new features from the menu. The server uses the RelativeDatabase class to store all information from the client. This class is allocated on the heap to assure data modularity and safe data sharing between the different commands.

A standard UML of this design pattern is:

11

Installing And Executing

To clone and run this application, you'll need Git installed on your computer. From your command line (running on localhost and port number 12345 - change if necessary):

# Clone this repository.
$ git clone https://github.com/TalMizrahii/AP1-KNN-Multithreaded-TCP-Server

# Go into the repository.
$ cd AP1-KNN-Multithreaded-TCP-Server

# Compile using makefile.
$ make

This command will create two .out files; server.out and client.out.

# To run the server with default port:
$ make run-server

To run the client with the default connection settings:

$ make run-client

To clean the .out files:

$ make clean

Authors

About

An AI-KNN algorithm system for classifying vectors, As part of the final project for Advanced Programming course, Bar-Ilan University.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages