0% found this document useful (0 votes)
16 views4 pages

Project Overview

This document outlines a Python-based file-sharing project that utilizes socket programming for server-client communication and tracks file metadata using a MySQL database. The server sends files to the client in 1 KB chunks while logging metadata about the transfers, and the client saves the received files locally. Additionally, it includes a FAQ section addressing common questions about sockets, SQL usage, and the program's applications and limitations.

Uploaded by

ucppndpapa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Project Overview

This document outlines a Python-based file-sharing project that utilizes socket programming for server-client communication and tracks file metadata using a MySQL database. The server sends files to the client in 1 KB chunks while logging metadata about the transfers, and the client saves the received files locally. Additionally, it includes a FAQ section addressing common questions about sockets, SQL usage, and the program's applications and limitations.

Uploaded by

ucppndpapa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Project Overview

This Python-based file-sharing project uses socket programming for communication between a
server and a client. The server sends a file to the client over a network, while the client
receives the file and saves it locally. Additionally, the project tracks metadata about the
transferred files using a MySQL database.
Server-Side Code
1. Creating MySQL Database (create_mysql_db function):
o This function sets up a MySQL database to store metadata about the transferred
files. It first connects to the MySQL server, creates a new database (file_metadata)
if it doesn’t already exist, and then creates a table (files) to store information like
the file name, size, type, and transfer status.
o SQL queries are used to create the database and table if they don't exist already.
2. Inserting File Metadata (insert_file_metadata function):
o After transferring a file, this function is called to insert the file's metadata (such as
the file name, size, type, and transfer status) into the files table in the MySQL
database.
o The database connection is established, and an INSERT SQL query is executed to
save the metadata.
3. Socket Setup and File Sending:
o The server creates a socket and binds it to a specified host and port
([Link] and port 8080 in your case).
o It waits for a connection from a client by calling [Link](), which blocks until a
client connects.
o Once the connection is established, the server prompts for a filename, calculates
the file size using [Link](), and opens the file in binary read mode ('rb').
o The file is read in 1 KB chunks ([Link](1024)) and sent to the client over the
socket using [Link]().
o After the file transfer is complete, the server closes the connection and inserts the
file metadata into the database, indicating that the transfer is "completed."
4. MySQL Database Operations:
o The database ensures that all file transfers are logged with metadata (file name,
size, type, and transfer status). The database could be useful for tracking files that
have been shared over the network.
Client-Side Code
1. Socket Connection:
o The client prompts the user to enter the host address of the server (the server’s IP
address) and the port number (8080).
o It creates a socket and attempts to connect to the server at the provided host and
port using [Link](). If the connection is successful, it prints a confirmation
message.
o The client also handles potential errors with a try-except block, ensuring the
program doesn’t crash if there are issues with the connection.
2. Receiving and Saving the File:
o Once connected, the client prompts the user to enter the name for the incoming
file (this is the name under which the file will be saved locally).
o The file is opened in binary write mode ('wb'), and the client begins receiving data
from the server in 1 KB chunks using [Link](1024).
o The received data is written to the file until the server has finished sending the file
(when file_data becomes empty).
o After the file transfer is complete, the client prints a success message indicating
the file has been successfully saved.
3. Error Handling and Cleanup:
o The client code is wrapped in a try-except block to catch any exceptions that may
occur during the connection or file transfer (e.g., if the server is unreachable).
o Regardless of whether the file transfer was successful or not, the client ensures
that the socket is closed with [Link]() in the finally block, which prevents potential
resource leaks.
How the System Works Together
1. Connection Setup:
o The server is waiting for a connection on a specific IP address and port
([Link] on port 8080).
o The client connects to the server by entering the server's IP address and port.
2. File Transfer:
o Once connected, the server sends the file to the client in chunks (1 KB at a time).
The client writes each chunk to a local file.
o This continues until the entire file is transferred.
3. Metadata Tracking:
o The server logs metadata (file name, size, type, transfer status) in the MySQL
database after the transfer is completed.
o This could help in future queries to find out which files have been successfully
transferred.
FREQUENTLY ASKED QUESTIONS IN VIVA AND THEIR
ANSWERS
1. What are sockets in python and what is their function?
Ans. A socket is an endpoint for sending or receiving data across a computer network. In
simpler terms, it's like a communication channel between two devices (or between two
applications on the same device) that allows them to exchange data.
2. What is the purpose of a client file and server file in the program?
Ans. The client’s main responsibility is to connect to the server by providing the server’s IP
address and port. It uses [Link]() to establish a connection to the server’s socket.
The server's primary job is to listen for incoming connections from clients. It opens a
socket and listens on a specific IP address and port, waiting for a client to connect.
The server uses [Link]() to wait for connection requests and [Link]() to accept a
connection from a client.
3. How have we used sql in the program?
Ans. In our file-sharing project, SQL is used to manage and store metadata related to the
files that are being transferred between the client and server. This helps you track the
details of each file shared in the system.
4. What are pros of using our file sharing program over any others ?
Ans. Our program is tailored to your specific needs. Unlike generic file transfer applications,
which may offer features you don’t need or lack features you do need, your program can be
easily adjusted to meet your exact requirements. For example:
 You can modify the file types supported, the chunk size for transfer, and even the
metadata being stored in the database.
 You have full control over how files are transferred, what protocols are used, and what
additional features (such as error handling, logging, etc.) to add.
5. What are real life applications of our program?
Ans. In a small or medium business setting, the program can be used for sharing files
between employees or departments within a local network. It allows businesses to:
 Transfer large files between offices or workstations (e.g., marketing materials, reports,
design files).
 Manage file transfer status by logging metadata like file name, size, and status,
which can help in tracking important documents.
 Simplify file management without relying on cloud storage, which can be expensive or
unnecessary for smaller businesses.
6. What type of files can be shared and what is the maximum size of a file that can be
shared using our program?
Ans. The program reads and transfers files in 1 KB chunks ([Link](1024)), which means
only small chunks of data are loaded into memory at a time. This means that, in
theory, there is no strict upper limit on file size in terms of memory usage.
Any type of file can be shared as long as the file is on the server and can be read by the
program.
7. Does our program transfer files over the internet and can we send a file from one device
to another via the internet?
Ans. By default, our program is set up to transfer files over a local network (LAN), not the
internet.
 The IP address we are using in the server code (host = "[Link]") is a local IP
address (specific to your local network). This means the server can only accept
connections from devices within the same network (like other devices in your home or
office).
 The client in the program connects to this local IP address, so it won’t work for sending
files over the internet unless additional configuration is done.

You might also like