GoDrop is a lightweight TCP server written in Go that receives files over a custom TCP protocol and stores them in a local directory. Perfect for learning low-level networking and file transfer mechanics.
- Accepts incoming TCP connections on
127.0.0.1:8080 - Handles multiple clients concurrently using goroutines
- Supports basic header-based protocol (
filenameandfilesize) - Displays a real-time progress bar while receiving files
- Graceful shutdown on SIGINT / SIGTERM (e.g., Ctrl+C)
- Automatically stores received files in the
goDropped/folder with a timestamped, IP-prefixed filename - Max file size limit of 10 MB
Client should send headers followed by the file bytes:
filename: my_file.txt
filesize: 12345
[RAW FILE BYTES...]
- Headers must be followed by a blank line (
\n) before the file data begins. filenameis the original file name.filesizeis the number of bytes to be read from the stream after the headers.
While receiving a file, GoDrop now shows a visual progress bar in the terminal:
Receiving: [##########----------] 50.00%
This updates in real time as the server writes chunks to disk.
Make sure you have Go installed. Then run:
go run main.goServer will start listening on 127.0.0.1:8080
You should see:
Serving on PORT 8080
START Reading incoming message...
START Reading file content from my_file.txt of size 12345
Receiving: [####################] 100.00%
File received successfully.
Saved my_file.txt in goDropped/1716271874_127.0.0.1_my_file.txt successfullyYou can test the server using nc (netcat) as a basic client:
(
echo -e "filename: test.txt\nfilesize: $(wc -c < test.txt)\n\n";
cat test.txt
) | nc 127.0.0.1 8080Make sure test.txt exists in the same directory.
Received files will be stored in the goDropped/ directory with names like:
goDropped/1716271874_127.0.0.1_test.txt
This includes a Unix timestamp and sender's IP to avoid collisions.
The server listens for system signals like SIGINT and SIGTERM to shut down cleanly:
^C
Server is being closed due to signal: interrupt
Stopping accepting connections...
Server shutdown
- Malformed headers? You'll get a 400 Bad Request.
- File too big? The server politely declines.
- Disk I/O errors? They're logged, and the connection is safely dropped.
- πΉ Go (Golang)
- π‘ TCP Sockets
- π§΅ Goroutines
- πΎ os, bufio, net, and time packages
MIT License. Do whatever you want. Just don't claim you wrote it first π.
Enjoy dropping files the Go way! π