Build a simple file-sharing application using the TCP/IP protocol stack with application protocols defined by each group.
- The centralized server keeps track of connected clients and the files they store.
- Clients inform the server about their local files without transmitting file data.
- Clients request files not in their repository from the server.
- The server identifies clients storing the requested file and sends their identities to the requesting client.
- The requesting client selects a source node, and the file is directly fetched without server intervention.
- Client code is multithreaded to support multiple simultaneous file downloads.
- Clients have a simple command-shell interpreter with two commands:
publish lname fname
: Adds a local file (lname
) to the client's repository with the namefname
. This information is conveyed to the server. For example,publish test.txt file.txt
fetch fname
: Requests a copy of the target file from other clients and adds it to the local repository. For example,fetch file.txt
- The server has a command-shell interpreter with two commands:
discover hostname
: Discovers the list of local files of the host namedhostname
, withhostname
is the IP and port seperated by a whitespace. For example,discover 192.168.1.8 50004
ping hostname
: Live-checks the host namedhostname
. For example,ping 192.168.1.8 50004
- Make sure you have Python installed on your system.
-
Clone the repository.
git clone https://github.com/nhatkhangcs/231-computer-network-assignment1.git
-
Navigate to the project directory.
cd 231-computer-network-assignment1
-
Configure the IP and port that the server bind to and ensure that the IP and port that the client connect to matches that server IP and port, configure also the IP that the client upload socket bind to so that they can be reached from other clients for fetching files
-
Run the server in folder
server
in a different terminal.python server.py
-
Run the server in folder
client
in a different terminal.python client.py
NOTE: If you want to test for multiple clients, navigate to folder test_client
. Here you can see list of client<x>
folders with same structure as the client
folder. The operation will be the same as above.
More description: On the client terminal, you will see 3 different addresses:
-
Sending address
: This is the address that is sending the request to the server. Serverping
anddiscover
to this address. -
Listening address
: This is the address that is listening requests from server. -
Upload address
: This is the address that is used to upload file to other clients.
If you want to use server to ping client, please ping the sending address of the client.
-
fetch fname1 fname2 fname3...
: Requests copies of the target files from other clients and adds them to the local repository multithreadedly. -
close
will close the client side. Server side will acknowledge the disconnection of the client. -
list
will list the client side's repository files.
list
will list the currently connecting clients.
If you'd like to contribute, please fork the repository and create a pull request.
This project is licensed under the HCMUT license.
Special thanks to Group 6 for their contribution to defining the application protocols.
Feel free to modify this template to suit your project structure and requirements.