A simple, secure, and cross-platform Python application for two-way file transfer and text processing using sockets and SSL/TLS.
This project demonstrates a client-server architecture where:
- The Client sends a text file (
send.txt) to the Server. - The Server receives the file, counts the frequency of each word, and saves the results.
- The Client can then request the processed file, which the Server sends back.
- All communication is encrypted.
Client Server
| |
|--- SSL/TLS Handshake ----------> |
| |
|--- Send File Size (8 bytes) ---> |
|--- Send File Data (send.txt) --> |
| |
| | <--- Receive & Process File
| | <--- Save result_for_client.txt
| |
|--- Send 'start' command -----> |
| |
| <--- Send File Size (8 bytes) ---|
| <--- Send File Data (result) ----|
| |
|--- Receive & Save result_file.txt|
- Secure — All data encrypted with SSL/TLS.
- Two-Way Transfer — Client-to-server and server-to-client communication.
- Simple Protocol —
[8-byte file size] + [file data]structure. - Cross-Platform — Tested between macOS (Client) and Windows (Server).
- Python 3.x
- Standard libraries:
socket,ssl,os,collections - OpenSSL (for generating certificates)
Run this command in your project directory:
openssl req -x509 -newkey rsa:2048 -nodes -keyout server.key -out server.crt -days 365This creates two files:
server.key— your private keyserver.crt— your public certificate
Ensure your send.txt file exists in the project folder and ends with a space and a period ( .) for accurate word counting.
You can run this in two modes:
- Localhost (Single Machine)
- Network Mode (Different Machines)
HOST = 'localhost'python3 server.pyExpected output:
Secure server listening on 0.0.0.0:5000...
python3 client.pyType start and press Enter when prompted.
You’ll find a new file:
client_result.txt
containing the word frequency output.
-
Find IP Address
ipconfig
Example:
IPv4 Address. . . . . . . . . . . : 172.20.10.9 -
Edit
server.pyHOST = '0.0.0.0'
-
Allow Through Firewall
- Open Windows Defender Firewall with Advanced Security (
wf.msc). - Create Inbound Rules:
- Open Windows Defender Firewall with Advanced Security (
Rule 1 — Python Port 5000:
- Type: Port → TCP → Port 5000
- Action: Allow the connection
- Profile: Domain, Private, Public
- Name: Python App Port 5000
Rule 2 — Allow Ping (for Testing):
- Type: Custom → Protocol: ICMPv4 → Echo Request
- Action: Allow connection
- Profile: Domain, Private, Public
- Name: Allow All Ping (ICMPv4-In)
-
Copy Certificate
Copyserver.crtfrom the Windows machine to the client project folder. -
Edit
client.pyHOST = '173.20.10.8' # Replace with your actual server IP
-
Test Connectivity
ping 173.20.10.8
If you get replies, connection is successful.
-
Run Client
python3 client.py
Type
startand press Enter.
This project is licensed under the MIT License.
See the LICENSE file for details.